How to make nginx work on deep links

I create a site which domain is https://resume.my.site.

What I’m trying to accomplish is to reverse proxy to https://my.site/resume when a user accesses https://resume.my.site

my config file is like:

location  /
{
    proxy_pass https://my.site/resume;
    proxy_set_header Host my.site;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    proxy_http_version 1.1;
    add_header X-Cache $upstream_cache_status;
}

But when I access https://resume.my.site, the content is https://my.site/ instead of https://my.site/resume.
What should I do about it?

That is the expected behavior of a reverse proxy, what you are looking for is a redirect. There are a few different ways to acheive this that are covered in this blog post.

Probably here is an example using the return directive that should work for what you are looking for:

server {
listen 443 ssl;
server_name resume.my.site;
return 301 https://my.site/resume;
}

Now this is very simple and would send any request to that subdomain to the specific URI, so any paths that were included(ie resume.my.site/foo) would end up at my.site/resume. This is probably file for this usecase, but may not be ideal for others.

1 Like

Thanks, but this way it will make my browser url follow, but I actually want the url to remain as resume.test.site

sorry about that, I misread your post. That config looks like it should do what you are expecting. Is there anything in the log files? It might also help to share the full config instead of the 1 location block.