因为涉及到两个域名以及两个 ssl 证书,采用了比较笨的方法。两个配置文件。
a.com.conf
server {
server_name
www.a.com a.com;
#301 配置
if ($host != '
www.b.com') {
rewrite ^/(.*)$
https://www.b.com/$1 permanent;
}
#其他的配置参数
}
server {
listen 80;
listen 443 ssl;
# SSL 证书配置
ssl_certificate /etc/letsencrypt/live/
www.a.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/
www.a.com/privkey.pem; #ssl_certificate /etc/letsencrypt/live/
www.b.com/fullchain.pem; #ssl_certificate_key /etc/letsencrypt/live/
www.b.com/privkey.pem; ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
server_name
www.a.com;
root /srv/www/
a.com/public_html; access_log /var/log/www/a.com.access.log;
error_log /var/log/www/a.com.error.log;
location / {
index index.php index.html index.htm;
if (-f $request_filename) {
expires 30d;
break;
}
try_files $uri $uri/ /index.php?$args;
}
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
location /nginx-status {
stub_status on;
access_log off;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.0-fpm.a.com.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /srv/www/
a.com/public_html$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_script_name;
include fastcgi_params;
}
}
-----------
b.com.conf
server {
listen 80;
server_name
www.b.com b.com www.a.com a.com;
return 301
https://www.b.com$request_uri;
}
server {
listen 80;
listen 443 ssl;
# SSL 证书配置
#ssl_certificate /etc/letsencrypt/live/
www.a.com/fullchain.pem; #ssl_certificate_key /etc/letsencrypt/live/
www.a.com/privkey.pem; ssl_certificate /etc/letsencrypt/live/
www.b.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/
www.b.com/privkey.pem; ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
server_name
www.b.com;
root /srv/www/
a.com/public_html; access_log /var/log/www/a.com.access.log;
error_log /var/log/www/a.com.error.log;
location / {
index index.php index.html index.htm;
if (-f $request_filename) {
expires 30d;
break;
}
try_files $uri $uri/ /index.php?$args;
}
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
location /nginx-status {
stub_status on;
access_log off;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.0-fpm.a.com.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /srv/www/
a.com/public_html$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_script_name;
include fastcgi_params;
}
}
@
LokiSharp #1