我使用Nginx从同一台PC运行前端和后端。
正面:反应(本地主机:3000)
后端: GO-Lang (本地主机:8080)
当您尝试从FE代码访问BE API时,可能会出现CORS错误。
为了克服这一问题,我使用nginx为FE创建代理,并在不同的路径上使用相同的端口(localhost:8000)
FE: /
BE: /server
nginx.conf
upstream server {
server localhost:8080;
}
upstream client {
server localhost:3000;
}
server {
listen 8000;
server_name localhost;
location / {
proxy_pass http://client;
}
location ~ /server/(?<section>.*) {
rewrite ^/server/(.*)$ /$1 break;
proxy_pass http://server;
}
}我用sudo nginx -s stop阻止了nginx
闭路终端
完全退出终端
但没有关掉我的电脑
问题
如何再次使用我的端口8000?
https://stackoverflow.com/questions/73729080
复制相似问题