Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am having two listener 80 and 777. Port 80 act as a reverse proxy. And port 777 does some extra stuff and want to redirect to port 80. How do I redirect to a different port in nginx? I was trying with rewrite but later figured out that it is only used for change of path

            listen  80;
            server_name     _;
            location / {
                    proxy_pass "http://upstream0;#" is included since links are not allowed in the post


            listen  777;
            server_name     _;
            #doing some other extra stuf
            //Want to redirect to port 80 under some condition


share|improve this question
return 302 $scheme://$server_name:80$request_uri;

That should do the trick.

share|improve this answer

Your Answer


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

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