1
所以我有多個域的多個讓我們加密ssl證書(每域一個)所有指向相同的應用程序(上游)。目前我正在使用下面的代碼。然而,這是相當多的代碼,特別是如果我不得不爲每個域複製它。所以我想知道是否有一種方法來組合它,這樣我的代碼只有一次,這會使維護起來更容易。Nginx設置多個域與單個ssl證書到相同的上游
https://www.any-domain-here
的重定向以及最後一個主要的服務器塊都是有問題的,因爲兩者都需要ssl證書,我需要爲所有不同的域包含這些證書。那麼有沒有辦法做到這一點,而不復制這些代碼塊?
############################
#
# Upstream
#
upstream upstream {
least_conn;
server app:8080;
}
upstream blog.upstream {
least_conn;
server app_nginx;
}
############################
#
# redirect all 80 to 443
# and allow Let's Encrypt
#
server {
server_name ~.;
listen 80;
listen [::]:80;
# config for .well-known
include /etc/nginx/includes/letsencrypt.conf;
location/{
return 301 https://$host$uri;
}
}
############################
#
# Redirect all www to non-www
#
server {
server_name "~^www\.(.*)$" ;
return 301 https://$1$request_uri ;
ssl_certificate /etc/letsencrypt/live/www.domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.domain.com/privkey.pem;
}
##########################
# HTTPS
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name domain.com;
location /blog/ {
proxy_set_header Host $host;
proxy_pass http://blog.upstream;
}
ssl_certificate /etc/letsencrypt/live/domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain.com/privkey.pem;
# access_log
access_log /var/log/nginx/access.log;
# proxy_pass config
location/{
# include proxy presets
include /etc/nginx/includes/proxy.conf;
proxy_pass http://domain.com$uri;
}
# general ssl parameters
include /etc/nginx/includes/ssl-params-with-preload.conf;
root /var/www/html;
}
你有沒有解決過這個問題? – Karem
對不起@Karem,以前沒有看到你的問題。 –