將 nginx-proxy 作為容器運行已經好幾年了。完美流暢,沒有任何問題。我正在使用 Docker-compose.yml:
services:
nginx-proxy:
image: jwilder/nginx-proxy:alpine
container_name: nginx-proxy
restart: always
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- ./nginx-certs:/etc/nginx/certs:ro
- ./nginx-vhost:/etc/nginx/vhost.d
- ./nginx-html:/usr/share/nginx/html
- ./uploadsize.conf:/etc/nginx/conf.d/uploadsize.conf
- ./subdomain1.mytld.com.conf:/etc/nginx/conf.d/subdomain1.mytld.com.conf:ro
現在我想使用 proxy_pass 存取本地 IP 位址上的另一個服務。問題。它僅適用於定義的這些子域之一,而不適用於同時啟動的兩個子域。
工作(subdomain1.mytld.com.conf 的內容):
server {
listen 443 ssl default;
ssl_certificate certs/mytld.com.crt;
ssl_certificate_key certs/mytld.com.key;
server_name subdomain1.mytld.com;
location / {
proxy_pass https://10.8.0.4/;
}
# server_name subdomain2.mytld.com;
# location / {
# proxy_pass http://10.8.0.4:8096/;
# }
}
不工作:
server {
listen 443 ssl default;
ssl_certificate certs/mytld.com.crt;
ssl_certificate_key certs/mytld.com.key;
server_name subdomain1.mytld.com;
location / {
proxy_pass https://10.8.0.4/;
}
server_name subdomain2.mytld.com;
location / {
proxy_pass http://10.8.0.4:8096/;
}
}
一旦我啟動其中兩個 server_names,整個 nginx 代理就會停止運作。我缺什麼?感謝您的協助
答案1
找到了小嗝嗝。伺服器標籤只允許使用“default”一次。因此,使用這樣的配置是有效的:
server {
listen 443 ssl default;
ssl_certificate certs/mytld.com.crt;
ssl_certificate_key certs/mytld.com.key;
server_name subdomain1.mytld.com;
location / {
proxy_pass https://10.8.0.4/;
}
}
server {
listen 443 ssl;
ssl_certificate certs/mytld.com.crt;
ssl_certificate_key certs/mytld.com.key;
server_name subdomain2.mytld.com;
location / {
proxy_pass http://10.8.0.4:8096/;
}
}