Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx Subdomain redirect to static URL

I have a domain that I can browse to via example.com:1234. Now I do not want to always have to type the port at the very end, but rather have nginx redirect me to the static URL when browsing a subdomain eg. status.example.com.

I have tried writing a redirect, but it didn't work at all.

server {
    listen 80;
    server_name status.example.com;
    return 301 $scheme://www.example.com:1234;
}

Where's my error? Is it the server block? Am I missing something basic here?

like image 812
Philipp Meissner Avatar asked Sep 17 '15 09:09

Philipp Meissner


1 Answers

Please try configuration as below,

server {
    listen 80;
    server_name status.example.com;
    location / {
        proxy_pass http://example.com:1234;
    }
}

For reference use NGINX Reverse Proxy and Module ngx_http_proxy_module

like image 195
mergenchik Avatar answered Sep 28 '22 07:09

mergenchik