1
LokiSharp 2017-11-29 15:17:40 +08:00
贴设置
|
2
nonozone OP 因为涉及到两个域名以及两个 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 |
3
xujiang 2017-11-29 15:27:56 +08:00
也请帮我看看这个问题
不怎么会用 nginx,我想把 xxxx.com 重定向为 xxxx.com/home,在 nginx 尝试了以下配置都没法生效 rewrite ^/ /home permanent; rewrite ^/ xxxx.com/home permanent; location / { rewrite ^/ /home permanent; } |
4
fhy1994 2017-11-29 15:35:52 +08:00
我的是这样配置的
``` # b.com.conf # 定义域名 geo $domain { default "https://a.com"; } server { listen 80; listen 443 ssl; client_max_body_size 100M; server_name b.com; return 301 $domain$request_uri; # 将 b.com 301 重定向到 a.com 以下配置省略 ``` |
5
0ZXYDDu796nVCFxq 2017-11-29 15:52:11 +08:00 1
更优雅的配置:
``` server { listen 80; server_name www.a.com a.com b.com; return 301 https://www.b.com$request_uri; } server { listen 443 ssl; server_name www.a.com a.com; return 301 https://www.b.com$request_uri; } server { listen 443 ssl; server_name b.com; return 301 https://www.b.com$request_uri; } ``` |
6
0ZXYDDu796nVCFxq 2017-11-29 15:53:28 +08:00 1
|
8
0ZXYDDu796nVCFxq 2017-11-29 16:54:00 +08:00 via iPhone
@nonozone 不用
|
9
msg7086 2017-11-29 20:58:51 +08:00
location = / { return 301 /home; }
这里用「 location /」 做跳转是不行的,要用「 location = /」。 |