[英]Redirect Old domain to New domain with ssl nginx
我正在嘗試將舊的SSL域重定向到新的SSL域。 但這給我發送了重定向循環。
我已經在Nginx虛擬主機中嘗試過此配置。
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name example.com www.example.com old-domain.com;
rewrite ^ https://www.example.com$request_uri permanent;
}
server {
#SSL Configuration
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
include snippets/ssl-example.com.conf;
include snippets/ssl-params.conf;
root /home/username/example/public;
index index.php index.html index.htm index.nginx-debian.html;
server_name example.com www.example.com old-domain.com;
rewrite ^ https://www.example.com$request_uri permanent;
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
請指導如何解決此問題。
在您的問題中,第二個rewrite
語句正在導致重定向循環。 正確的解決方案是將server
塊分成兩部分,然后從一個重定向到另一個,與從http
重定向到https
方式幾乎相同。 為此,您可以使用第一個server
塊。
帶有default_server
的server
塊不需要server_name
指令,因為它始終會響應所有不匹配的服務器名稱。 有關詳細信息,請參見此文檔 。
假設這些服務器是此配置中唯一的https
服務器,並且兩個server
塊都共享相同的SSL配置(如您的注釋所建議),則摘要文件可以移到上方,從而由兩個server
塊繼承 。
最后,主server
塊中的server_name
指令僅列出不被重定向的服務器名稱。
例如:
include snippets/ssl-example.com.conf;
include snippets/ssl-params.conf;
server {
listen 80 default_server;
listen [::]:80 default_server;
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
return 301 https://www.example.com$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name www.example.com;
...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.