0

I'm trying to run a single react app on a separate port and using proxy pass from nginx to location '/app'

"http://localhost/app" -> React Application

The application is running under PM2 using its generated build with the command: 'pm2 serve build 3002'.

My thought was i do all this tested locally and then will port it to my own domain.

I've swapped 'localhost' for '127.0.0.1' just in case that had anything to do with it.

From online tutorials i've ended up with the following in my nginx "../sites-available/my_domain" file

server {
        listen 80;
        listen [::]:80;

        server_name localhost;

        location / {
                root /var/www/my_domain/html;
                index index.html index.htm index.nginx-debian.html;
                try_files $uri $uri/ =404;
        }

        location /app {
                proxy_pass http://localhost:3002;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
        }
}

If i type "http://localhost:3002" into the url it works fine however "http://localhost/app" does not work and shows 404 error.

Side-note: "http://localhost" works fine and directs to the index.html stored at root.

2
  • Is this a react only app or a full stack react express app Commented May 30, 2019 at 2:06
  • if i understand you correctly @iqbal125 react only app Commented Jun 3, 2019 at 0:54

1 Answer 1

0

In your configuration, you are missing the / after the server address, something like : location /app { proxy_pass http://localhost:3002/;

Sign up to request clarification or add additional context in comments.

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.