I am totally newbie on NGINX reverse proxy solution and its seems to getting hard to understand all the terminology. I am looking for a solution as follows. I would really appreciate anybody's help to configure the same.
We have an internal web server which we would like to publish at WWW site but don't want customer to see internal server URL. As example:
Customer access www.mycompany.com/track --> NGINX read the track and then redirect URL to internal server.com.au/tracker . We dont want customer to see this address.
Any suggestion?
Cheers,
Sandy
It is much better in this case to use the proxy. Rewrites are meant for URLs within the same domain or to redirect the client (which would show in the url).
Try this:
location / {
proxy_pass http://internal.example.com/;
proxy_set_header Host $host;
}
Rewriting on nginx is quite the same than on Apache :) The syntax varies.
When Apache uses RewriteRule, nginx uses rewrite. May I suggest you this reference http://wiki.nginx.org/HttpRewriteModule ? Check 2.4 and 2.5 for rewriting-specific documentation. You'll find information about the rewrite syntax, and rewriting options.
There is a quick example from above, if you just need the basic syntax :
rewrite ^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 break;
By the way, if you want to work from examples, you can transform your Apache .htaccess file into a piece of nginx configuration, using this tool : http://winginx.com/htaccess
Related
I have a single entrypoint into a microservice application which is done via NGINX proxying in the main frontend application.
I have another frontend microservice (Let's call it FE2) that is not accessible from outside.
My NGINX config of the primary frontend looks the following:
set $fe2 "<kubernetes service address of my second frontend app>";
location /fe2 {
rewrite ^/fe2/(.*)$ /$1 break;
proxy_pass http://$fe2;
proxy_redirect / /fe2;
proxy_set_header Host $host;
}
So in theory, what should happen is that all requests that come to /fe2 should be proxies to my second frontend application via the rewrite and proxypass directives.
The proxy_redirect directive is there in place to handle all the redirects that are in place in my second frontend application.
The first thing I am concerned about are the elements of my second frontend that have href properties - will they be able to send requests to proper endpoints (xxx/fe2/somepage instead of just xxx/somepage)? The second frontend application is a webpack bundle, so all the page changes should not even reach NGINX.
Second thing is more of an issue - I already deployed this setup, but noticed that when I go to xxx/fe2/ the page is just blank, and the error message states Uncaught SyntaxError: Unexpected token '<' (at main.someid.js:1:1) . The file has a .js extension, but the actual code inside is HTML, so I don't know what's going on in there(
I know that the question is complicated, but have any of you folks tried the same setup, or are there any alternatives using NGINX?
I would appreciate any help on this matter!
I'm basically trying to have nginx redirect:
https://website1.com/program_video/programXXX.mp4
to
http://website2.com/ProgramsVideos/programXXX.mp4
Given that "XXX" is the id of the video and might change.
I've been wandering around stackoverflow and nginx directory but wasn't able to get anything to work.
Last thing I tried was:
rewrite "https://website1.com/program_video/([a-zA-Z0-9]{23})\.mp4)$" http://website2.com/ProgramsVideos/$1 permanent;
But it doesn't redirect anything...
Any help would be much appreciated.
My demand is as follows:
If I request an URL like this
http://example.com/10-10-43-3
the server gets the resource from
http://10.10.43.3
and response to me.
10-10-43-3 can be arbitrary URL that replace '.' with '-'.
How can I achieve it through nginx? Something like location and proxy_pass?
The following should help get you started.
location /10-10-43-3 {
proxy_pass http://10.10.43.3;
}
If there are other redirects that need to be accounted for, you will most likely need to add variations to the above as well as regular expression handling.
I suspect this will be quite simple, yet I can't seem to get my head around the nginx rewrite system. Hopefully someone could chime in and help me out?
Quite simply, I need..
http://example.com/?c=foo
to to be rewritten to...
http://foo.example.com
Thank-you in advance if you've taken pitty on this nginx noob :)
I'll keep having a go at this, and in the unlikely event I hit a 'eureka' moment, I'll update this to help anyone who's having/will ever have this similar 'problem'.
Cheers.
Actually, it is impossible to make internal redirect to other domain in Nginx. But there are two available solutions:
1) Simple: make redirect to specified address. Example:
if ( $arg_c ) {
rewrite ^ http://$arg_c.example.com;
}
2) Complex: if you use Nginx as a proxy between php-fpm, apache or something else, you could set the Host header in this way::
set $new_host example.com;
if ( $arg_c) {
set $new_host $arg_c.example.com;
}
and pass it as a parameter:
proxy_set_header Host $new_host;
I'm having a difficult time figuring out how should I make a hole bunch of redirects (301) to Nginx. Maybe you can give me some help.
Basically I have a few hundred of url's like this one above:
http://www.website.com/product/intl/bg-BG/browserchoice/download.html?track=1871
And I need to redirect to:
http://www.website.com/home/download/download.php?prod=browser&track=1871
How should I do it? (*bg-BG from source is the single variable that changes)
Please help me.
Thanks.
Please try this, it peforms internal redirect in nginx:
rewrite ^/product/intl/.*/browserchoice/download.html$ /home/download/download.php?prod=browser&$args break;
But if you really want redirect (this is not a good choice) :
rewrite ^/product/intl/.*/browserchoice/download.html$ http://www.website.com/home/download/download.php?prod=browser&$args permanent;
I also suggest you to read official documentation here http://wiki.nginx.org/HttpRewriteModule