How to redirect single URL in Nginx?
location ~ /issue([0-9]+) { return 301 http://example.com/shop/issues/custom_isse_name$1; }
location ~ /issue([0-9]+) { return 301 http://example.com/shop/issues/custom_isse_name$1; }
replace include fastcgi_params; with include fastcgi.conf; and remove fastcgi_param SCRIPT_FILENAME … in nginx.conf
You can use server-snippet annotation. This seems like exactly what you want to achieve.
You can match the different URLs with server {} blocks, then inside each server block, you’d have the reverse proxy settings. Below, an illustration; server { server_name client.example.com; # app1 reverse proxy follow proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://x.x.x.100:80; } server { server_name client2.example.com; # app2 reverse proxy settings follow … Read more
If you use a URI with a proxy_pass statement within a regular expression location, you need to build the entire URI using one or more variables. See this document for details. So the alternatives are to (1), capture the URI from the location expression and add it to the proxy_pass statement. For example: location ~ … Read more
It’s not only possible, it’s easy: in nginx the response header values are available through a variable (one per header). See http://wiki.nginx.org/HttpCoreModule#.24sent_http_HEADER for the details on those variables. In your examle the variable would be $sent_http_My_custom_header.
add_header works as well with proxy_pass as without. I just today set up a configuration where I’ve used exactly that directive. I have to admit though that I’ve struggled as well setting this up without exactly recalling the reason, though. Right now I have a working configuration and it contains the following (among others): server … Read more
Change listen option to this in your catch-all server block. (Add default_server) this will take all your non-defined connections (on the specified port). listen 80 default_server; if you want to push everything to index.php if the file or folder does not exist; try_files $uri /$uri /index.php; Per the docs, It can also be set explicitly … Read more
You need to use the alias directive for location /static: server { index index.html; server_name test.example.com; root /web/test.example.com/www; location /static/ { alias /web/test.example.com/static/; } } The nginx wiki explains the difference between root and alias better than I can: Note that it may look similar to the root directive at first sight, but the document … Read more
In a running server, the nginx’s configuration being used here is: # Requests for socket.io are passed on to Node on port 3000 location ~* \.io { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-NginX-Proxy false; proxy_pass http://localhost:3000; proxy_redirect off; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection “upgrade”; }