404 Not Found 404 Not Found| NGINX

juzqafwq  于 5个月前  发布在  Nginx
关注(0)|答案(1)|浏览(64)

我想让我的网站在没有端口3000的域上可用,我知道React JS和Nginx不能使用相同的端口,所以下面你可以看到我的Nginx文件的配置:

location / {
   # try_files $uri $uri.html $uri/ @extensionless-php;
     proxy_set_header Accept-Encoding "";
     proxy_pass http://localhost:3000;
     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;
}

location /static/ {
     proxy_set_header Accept-Encoding "";
     proxy_pass http://localhost:3000;
     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;
}

字符串
当我转到https://example.com时,我在控制台中看到一个空白页面和以下错误:Image
但是当我转到http://example.com:3000时,它都可以正常工作,没有任何问题,那么我如何才能使它在https://example.com上工作呢?

0aydgbwb

0aydgbwb1#

从你的描述中,我假设你正在使用npm run start/yarn start运行react应用程序,这是为你的开发环境设计的。然而,在你的服务器上运行应用程序,会把它带到“生产”环境。
运行npm run build/yarn build会以编译和优化的格式提供所有源文件。您可以将它们放在服务器上,并立即由nginx提供(如使用try_files),而无需运行单独的服务器或将请求作为代理传递。
如果你想只作为代理运行你的应用(例如,这是你的开发环境),你必须修复nginx配置中的路径,因为你的/static/位置不会转发到/static/路径。你可以通过将路径添加到proxy_pass或删除完整的第二个位置块来实现这一点-它将等同于第一个。
供您参考:

相关问题