我的需求是通过地址url访问不同的docker容器。
例如:
- www.zhengjiyuan.top为主网站,用于展示。
- www.zhengjiyuan.top/chatgpt,用于使用docker容器A。
- www.zhengjiyuan.top/halo,用于使用docker容器B。
我使用的方法是(失败的)
- 创建一个静态网站。
- 在静态网站中使用反向代理。
location ^~ /chatgpt-next-web {
proxy_pass http://172.0.0.1:40042;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_http_version 1.1;
add_header X-Cache $upstream_cache_status;
proxy_ssl_server_name off;
proxy_ssl_name $proxy_host;
add_header Cache-Control no-cache;
add_header Strict-Transport-Security "max-age=31536000";
}
- 尝试访问 chatgpt-next-web 返回 ERR_SSL_PROTOCOL_ERROR。
- 使用 IP + 端口 也无法访问。
目前我已进行的操作有:
- 配置了SSL证书。
- 开放 80、443、 40042等端口。
openrestry配置文件:
server {
listen 80 default_server;
listen 443 ssl http2 default_server;
server_name www.zhengjiyuan.top;
index index.php index.html index.htm default.php default.htm default.html;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
access_log /www/sites/www.zhengjiyuan.top/log/access.log main;
error_log /www/sites/www.zhengjiyuan.top/log/error.log;
location ^~ /.well-known/acme-challenge {
allow all;
root /usr/share/nginx/html;
}
root /www/sites/www.zhengjiyuan.top/index;
add_header Strict-Transport-Security "max-age=31536000";
include /www/sites/www.zhengjiyuan.top/proxy/*.conf;
ssl_certificate /www/sites/www.zhengjiyuan.top/ssl/fullchain.pem;
ssl_certificate_key /www/sites/www.zhengjiyuan.top/ssl/privkey.pem;
ssl_protocols TLSv1.3 TLSv1.2 TLSv1.1 TLSv1;
ssl_ciphers ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:!aNULL:!eNULL:!EXPORT:!DSS:!DES:!RC4:!3DES:!MD5:!PSK:!KRB5:!SRP:!CAMELLIA:!SEED;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
error_page 497 https://$host$request_uri;
proxy_set_header X-Forwarded-Proto https;
}