【问题标题】:Having issues displaying react app on nginx server at domain在域的 nginx 服务器上显示反应应用程序时出现问题
【发布时间】:2021-01-26 07:15:42
【问题描述】:

我正在尝试添加一个将显示在 mydomain.com/react-app 的反应应用程序。我对 nginx 很陌生,这是我第一次在 Linux 服务器上托管网站。站点 mydomain.com 已经在此服务器上存在了一段时间,我使用 react 构建了站点的另一部分,并希望将其托管在 /react-app。这是我的/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;
    }
}

我可以在 IP 地址0.0.0.0/react-app 但不能在mydomain.com/react-app 上服务和访问该站点。当我访问该地址时,我只是收到 404 nginx 错误。

【问题讨论】:

    标签: reactjs linux nginx


    【解决方案1】:

    如果您的服务器应用程序在例如端口 3500 上运行:

    server {
        listen 80;
        listen [::]:80;
    
        server_name mydomain.com/ www.mydomain.com/;
    
        location / {
                proxy_pass http://localhost:3500;
        }
    }
    

    【讨论】:

    • 好吧,我试试。 proxy_pass 应该是反应应用程序正在运行的本地主机吗?为了让路径正常工作,它应该是位置/react-app吗?谢谢!
    猜你喜欢
    • 1970-01-01
    • 2019-01-20
    • 1970-01-01
    • 2019-03-14
    • 2019-11-19
    • 2020-04-21
    • 1970-01-01
    • 1970-01-01
    • 2019-11-26
    相关资源
    最近更新 更多