0
我有一個nginx多個服務器名稱,並需要重定向到https特定的服務器名稱。Nginx規則重定向一個特定的服務器名稱
隨着我的配置(如下圖),我得到了錯誤ERR_TOO_MANY_REDIRECTS
我的conf:
# /etc/nginx/sites-available/k2cloud_staging
upstream puma_k2cloud_staging {
server unix:/home/outracoisa/k2cloud/shared/tmp/sockets/puma.sock fail_timeout=0;
}
server {
listen 8080;
client_max_body_size 4G;
keepalive_timeout 10;
error_page 500 502 504 /500.html;
error_page 503 @503;
server_name contoso.com www.contoso.com contoso.com.br www.contoso.com.br contoso.sapo.pt www.contoso.sapo.pt;
root /home/outracoisa/k2cloud/current/public;
try_files $uri/index.html $uri @puma_k2cloud_staging;
if ($host ~* www\.(.*)) {
set $host_without_www $1;
rewrite ^(.*)$ http://$host_without_www$1 permanent;
}
rewrite ^/rio/?$ http://contoso.com/rio/pt-BR permanent;
rewrite ^/lisboa/?$ http://contoso.sapo.pt/lisboa/pt-PT permanent;
if ($host ~ contoso.com(\.br)) {
rewrite ^/?$ http://contoso.com/rio/pt-BR permanent;
}
if ($host = contoso.sapo.pt) {
rewrite ^/?$ http://contoso.sapo.pt/lisboa/pt-PT permanent;
}
location ~ ^/(rio|lisboa) {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://puma_k2cloud_staging;
# limit_req zone=one;
access_log /home/outracoisa/k2cloud/shared/log/nginx.access.log;
error_log /home/outracoisa/k2cloud/shared/log/nginx.error.log;
}
########## Ramos #####
if ($scheme != "https") {
set $a x;
}
if ($host = contoso.sapo.pt) {
set $a "${a}y";
}
if ($a = xy) {
rewrite ^(.*) https://$host$1 permanent;
break;
}
################
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
location = /50x.html {
root html;
}
location = /404.html {
root html;
}
location @503 {
error_page 405 = /system/maintenance.html;
if (-f $document_root/system/maintenance.html) {
rewrite ^(.*)$ /system/maintenance.html break;
}
rewrite ^(.*)$ /503.html break;
}
if ($request_method !~ ^(GET|HEAD|PUT|PATCH|POST|DELETE|OPTIONS)$){
return 405;
}
if (-f $document_root/system/maintenance.html) {
return 503;
}
location ~ \.(php|html)$ {
return 405;
}
}
任何人都可以幫我解決這個問題嗎?
使用一個單獨的'server'塊。 –