Mobile app version of vmapp.org
Login or Join
Bethany197

: Nginx redirect subdomain to a url path I have a requirement where I need to point xyz.tld to abc.def.tld. Additionally I would have to internally rewrite/redirect abc.def.tld to def.tld/abc. So

@Bethany197

Posted in: #Cname #Nginx #Webserver

I have a requirement where I need to point xyz.tld to abc.def.tld. Additionally I would have to internally rewrite/redirect abc.def.tld to def.tld/abc. So the final result here I intend is when I visit xyz.tld, it should render contents of def.tld/abc without URL change. What is the idle way of achieving this? I have tried proxy_pass but when I do proxy pass, some static files (js files) at the root folder get messed up. Here is what I tried. Additionally I am not able to point xyz.tld to abc.def.tld using CNAME (as it resolves to IP).

server {
listen 80;
server_name ~(?<subdomain>w+).def.tld;
location / {
proxy_pass 127.0.0.1:3000/$subdomain$request_uri; proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host; # pass the host header - wiki.nginx.org/HttpProxyModule#proxy_pass
proxy_http_version 1.1; # recommended with keepalive connections - nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_http_version
# WebSocket proxying - from nginx.org/en/docs/http/websocket.html proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}


Will a permanent redirect help? But if I do this, can I still point xyz.tld to abc.def.tld?

10% popularity Vote Up Vote Down


Login to follow query

More posts by @Bethany197

0 Comments

Sorted by latest first Latest Oldest Best

Back to top | Use Dark Theme