Mobile app version of vmapp.org
Login or Join
Shanna517

: Nginx proxy on domain only I have setup a server block with a proxy in nginx which works when I hit the service with an a directory. For example I can access gs.geolytix.net/geoserver with

@Shanna517

Posted in: #Nginx #Proxy

I have setup a server block with a proxy in nginx which works when I hit the service with an a directory.

For example I can access gs.geolytix.net/geoserver with this conf.

server {
listen 80;
server_name gs.geolytix.net;
location /geoserver {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass 138.68.137.90:8080/geoserver; }
}


So far so good. What I would like to achieve though is that I get to the same address but only address gs.geolytix.net in the browser. Without a directory. If I change the location to / alone I go to gs.geolytix.net the response is gs.geolytix.net//

Thanks,
Dennis

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Shanna517

2 Comments

Sorted by latest first Latest Oldest Best

 

@Alves908

You can do this by having a "URI" in the proxy_pass, which acts a sort of implicit rewrite:

location / {
# Note the "/" at the end of the proxy_pass, this will cause it to
# replace the location block (/ in this case) with "/geoserver/"
# when talking to origin.
# So gs.geolytix.net/test becomes 138.68.137.90:8080/geoserver/test
proxy_pass 138.68.137.90:8080/geoserver/; }

10% popularity Vote Up Vote Down


 

@Shanna517

If you want the root URI / to quietly map to /geoserver, then a simple method is with an internal rewrite:

location = / {
rewrite ^ /geoserver last;
}


EDIT: If you want an external rewrite, use the same location block with a return statement:

location = / {
return 302 /geoserver;
}


The location directive is documented here. The rewrite and return directives are documented here.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme