Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to setup nginx with a domain I have. Because I only have a single cert, I want to use subfolders to access services I am hosting.

When I hit 'htps://domain.com/myservice' it proxies the request to '192.168.0.4:9081', but the url the user sees is now 'htps://domain.com/login.html'. No login.html exists in my root folder. The url needs to look like 'htps://domain.com/myservice/login.html'

I've tried playing with proxy_redirect but I can't seem to figure it out. What am I missing?

domain.conf:

server {
    listen                  80;
    server_name     domain.com;
    rewrite                 ^ https://$server_name$request_uri? permanent;
}

server {
    listen                                  443;
    server_name                     domain.com;

    ssl                                     on;
    ssl_certificate                 /etc/nginx/cert/cert.crt;
    ssl_certificate_key     /etc/nginx/cert/cert.key;

    access_log                      /var/log/domain.com.access.log;
    error_log                               /var/log/domain.com.error.log;

    root                                    /usr/share/nginx/html;
    #index                                  index.html;

    location / {
            index  index.html;
    }

    location /myservice{
            include                         /etc/nginx/proxy.conf;
            proxy_pass                      http://192.168.0.4:9081/;
    }
}

proxy.conf:

client_max_body_size 10m;
client_body_buffer_size 128k;

#Timeout if the real server is dead
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;

# Advanced Proxy Config
send_timeout 5m;
proxy_read_timeout 240;
proxy_send_timeout 240;
proxy_connect_timeout 240;

# Basic Proxy Config
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_redirect     off;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_cache_bypass $cookie_session;
proxy_no_cache $cookie_session;
proxy_buffers 32 4k;
share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.