我有一个在docker容器内运行的小快递应用程序。终端可通过http://localhost:8888/api/run
在本地访问。使用以下命令运行docker容器:
docker run -dp 8888:8888 code-editor
我配置NGINX使用location块从docker提供响应:
服务器{
server_name www.baseURL.tech baseURL.tech;
-------------------CONNECT WITH APP INSIDE DOCKER--------------------
location /compiler {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8888/;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
-------------------CONNECT WITH MAIN NODE APP--------------------
location / {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8000/;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
被调用的路径是https://baseURL/compiler/api/run
,作为主站https://baseURL
的ajax请求,但它返回404。
你有
location /compiler
将导致Nginx传递整个URL,即compiler/api/run
到Express应用程序。您希望它删除compiler
部分,最简单的方法是在位置的末尾添加斜杠,如
location /compiler/
那么Nginx只会把api/run
传递给Express。