我使用nginx将代理反向到多个被篡改的应用程序,这是可行的。但我找不到更重要的工作。
我的nginx配置包括:
location ^~ /apps/portainer {
proxy_http_version 1.1;
proxy_set_header Connection "";
set $upstream portainer:9000;
proxy_pass http://$upstream;
}页面没有正确加载(css和js不加载)。nginx错误日志:
打开()“/var/www/html/app/main.11b0c8b84d24581.js”失败(2:没有此类文件或目录),请求:"GET /app/main.11b0c8b84d24581.js HTTP/2.0“
我不明白nginx为什么要提供静态文件--所有东西都应该代理到portainer。(这条路是错的,尽管不相关)。
对此是否有常规修复,而不涉及regex?顺便说一句,如果您不介意在位置块中使用regex,下面@EchoMike444 444给出的答案是非常好的。
发布于 2019-10-24 14:08:30
通过遵循来自https://portainer.readthedocs.io/en/stable/faq.html的配置,我能够连接到http://127.0.0.1/apps/portainer/
您缺少管理websocket连接的部分
我的ngnix default.conf
upstream portainer {
server portainer:9000;
}
server {
listen 80;
location /apps/portainer/ {
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_pass http://portainer/;
}
location /apps/portainer/api/websocket/ {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
proxy_pass http://portainer/api/websocket/;
}
}我的docker-compose.yaml
version: '3.7'
services:
portainer:
image: portainer/portainer
restart: always
command: -H tcp://10.10.0.1:2375
ports:
- target: 8000
published: 8000
protocol: tcp
- target: 9000
published: 9000
protocol: tcp
volumes:
- portainer_data:/data
nginx:
image: nginx
volumes:
- ${PWD}/default.conf:/etc/nginx/conf.d/default.conf:ro
command: ["/bin/sh","-c","exec nginx -g 'daemon off;'"]
restart: always
ports:
- target: 80
published: 80
protocol: tcp
mode: host
volumes:
portainer_data:注释后的UPDATED
因为nginx在启动时执行dns解析,所以您希望使用一个变量,因此default.conf变成这样。
resolver 127.0.0.11 valid=30s;
resolver_timeout 5s;
server {
listen 80;
location ~* ^(/apps/portainer)(/api/websocket/.*)$ {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
set $upstream http://portainer:9000$2;
proxy_pass $upstream ;
}
location ~* ^(/apps/portainer)(/.*)$ {
proxy_http_version 1.1;
proxy_set_header Connection "";
set $upstream http://portainer:9000$2;
proxy_pass $upstream;
}
}https://serverfault.com/questions/989286
复制相似问题