Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
285 views
in Technique[技术] by (71.8m points)

reactjs - Having issues displaying react app on nginx server at domain

I'm trying to add a react app that will be displaying at mydomain.com/react-app. I'm pretty new to nginx and this is my first go at hosting a site on a Linux server. The site mydomain.com has existed on this server for some time and I built another part of the site using react and would like to host it at /react-app. This is my /etc/nginx/sites-available/react-app:

server {
    listen 80;
    server_name 0.0.0.0;

    location /react-app {
        alias /var/www/react-app/build/;
        index index.html;
        try_files $uri $uri/ /build/index.html;
    }
}

I'm able to serve and visit the site at the IP location 0.0.0.0/react-app but not mydomain.com/react-app. I just get a 404 nginx error when I visit that address.

question from:https://stackoverflow.com/questions/65892801/having-issues-displaying-react-app-on-nginx-server-at-domain

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If your server app running for example on port 3500:

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

    server_name mydomain.com/ www.mydomain.com/;

    location / {
            proxy_pass http://localhost:3500;
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...