search

Home  >  Q&A  >  body text

How to use nginx to forward port 9000 to port 80 locally?

I want to try the third-party login API, but the other party will only redirect to port 80. I want to forward port 9000 to port 80 locally. I wrote it under /etc/ngnix/sites-enabled/ A file and then run
service nginx reload

  1 server {
  2         listen 80;
  3         server_name 127.0.0.1;
  4         location / {
  5                 proxy_pass http://localhost:9000;
  6                 proxy_set_header Host $host;
  7                 proxy_set_header X-Real-IP $remote_addr;
  8                 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  9                 proxy_redirect off;
 10         }
 11 }

I referred to some online resources, but there were no local examples. I tried it myself, but I still couldn't access my 127.0.0.1:9000## from 127.0.0.1 # There is a default file under the configuration file directory. Does it have any impact? Is there anything wrong with the configuration file I wrote?

習慣沉默習慣沉默2743 days ago538

reply all(2)I'll reply

  • 大家讲道理

    大家讲道理2017-05-16 17:28:34

    will

    server_name 127.0.0.1
    Change to

    server_name localhost
    

    Try it

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-16 17:28:34

    server_name must be configured as a domain name, otherwise nginx itself uses 127.0.0.1. Wouldn’t it be impossible to tell whether you are accessing nginx or the server on port 9000?

    reply
    0
  • Cancelreply