nginx

How to create a reverse proxy on Nginx?


I have a web app running on localhost:5000.

I would like to serve this app using Nginx and an external domain.

I configured Nginx as follows :

server {
        server_name example.com www.example.com;
        listen 80;
        listen [::]:80;

        access_log /var/log/nginx/reverse-access.log;
        error_log /var/log/nginx/reverse-error.log;

        location / {
                    proxy_pass http://127.0.0.1:5000;
                    proxy_redirect http://127.0.0.1:5000 /;
  }
}

After restarting Nginx, what this code does is when typing example.com on Chrome, it redirects (on the client side) to 127.0.0.1:5000 which results obviously in the error : This site can’t be reached

What I need, is not a redirection on the client side but, serving the URL http://127.0.0.1:5000 on the server side and send it back to the end user.

How can I achieve this?


Solution

  • Remove the proxy_redirect line. Proxy_pass should be enough.