我在vps中运行节点js应用程序。
这是我的nginx配置:
server {
listen 80;
server_name xxx.xxx.xxx.xxx;
#access_log logs/ecommerce.access.log main;
location /ecommerce/api/ {
proxy_pass http://127.0.0.1:8000/api/;
}
location /ecapp/ {
proxy_pass http://127.0.0.1:3000/;
}
}localhost:8000/api是使用mongodb地图的后端服务器。我已经通过使用邮递员和发送请求确认了这一工作。
localhost:3000是最前端的应用。
前端应用程序只在以下情况下才能通过我的ip的公共ip工作:
server {
listen 80;
server_name xxx.xxx.xxx.xxx;
#access_log logs/ecommerce.access.log main;
location /ecommerce/api/ {
proxy_pass http://127.0.0.1:8000/api/;
}
location / {
proxy_pass http://127.0.0.1:3000/;
}
}/以外的位置(如/ecapp/ )将无法工作。只有地点/工作地点。
我想通过http://my_vps_ip/以外的http://my_vps_ip/ecapp来访问前端应用程序。
任何帮助都是非常感谢的。
发布于 2021-11-18 22:35:05
当位置设置为/ecapp/时,当我加载http://my_副总裁_ip/ecapp并检查我得到的控制台时:
GET http://my_public_vps_addr/static/js/bundle.js
GET http://my_public_vps_addr/static/js/0.chunk.js
GET http://my_public_vps_addr/static/js/main.chunk.js
Loading failed for the <script> with source “http://my_vps_public_ip/static/js/bundle.js”.
Loading failed for the <script> with source “http://my_vps_ip_public_ip/static/js/0.chunk.js”. ecapp:30:1
Loading failed for the <script> with source “http://my_vps_ip_public_ip/static/js/main.chunk.js”. ecapp:30:1 它为什么要寻找静态文件?在/var/www/html/下没有静态目录。
电子商务项目的源代码如下:https://github.com/kaloraat/react-node-ecommerce
https://unix.stackexchange.com/questions/678060
复制相似问题