Welcome! Log In Create A New Profile

Advanced

How to get nginx to redirect to another path only if the root path is requested?

January 26, 2018 02:24PM
How to get nginx to redirect to another path only if the root path is requested?

Here is part of my server configuration:

server {
listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 default_server ipv6only=on; ## listen for ipv6

# Make site accessible from http://localhost/
server_name wiki wiki.leerdomain.lan;

# Note: There should never be more than one root in a
# virutal host
# Also there should never be a root in the location.
#root /var/www/nginx/;

rewrite ^/$ /rootWiki/ redirect;


location ^~ /rootWiki/ {
resolver 127.0.0.1 valid=300s;
access_log ./logs/RootWiki_access.log;
error_log ./logs/RootWiki_error.log;
proxy_buffers 16 4k;
proxy_buffer_size 2k;
proxy_set_header Host $host;
proxy_set_header X-Real_IP $remote_addr;
rewrite /rootWiki/(.*) /$1 break;
proxy_pass http://192.168.1.200:8080;
}

location ^~ /usmle/ {
access_log ./logs/usmle_access.log;

...

When I configure it as above I am unable to access any of the sub-locations under root...but the root directory does forward to /rootWiki/ but I receive a 502 Bad Gateway instead of the application on port 8080.

When I remove the line:

rewrite ^/$ /rootWiki/ redirect;

I'm able to access the rootWiki application, and all the sub locations from root just fine.

It seems to me like it should work but it does not appear to.
Subject Author Posted

How to get nginx to redirect to another path only if the root path is requested?

leeand00 January 26, 2018 02:24PM

Re: How to get nginx to redirect to another path only if the root path is requested?

Francis Daly January 27, 2018 08:28AM

Re: How to get nginx to redirect to another path only if the root path is requested?

leeand00 January 27, 2018 09:36PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 202
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready