5

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?

1

1 Answer 1

9

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

3
  • Thanks, this does work like a charm :) Could you point out what the problem with my config was? Sep 17, 2015 at 9:51
  • 1
    return 301 is a HTTP redirect, which will redirect browser to argument provided ($scheme://www.example.com:1234), but proxy will be a proxy between browser and target.
    – mergenchik
    Sep 17, 2015 at 9:52
  • Ahh, sounds reasonable. Thank you very much for the input. Sep 17, 2015 at 9:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.