[英]Nginx rewrite HTTP to HTTPS says redirect loop?
我正在尝试将所有HTTP通信重定向到HTTPS,因此当我转到www.domain.com时,它将转到https://www.domain.com 。 这是我当前的.conf文件-
server {
listen 80;
#listen [::]:80;
server_name www.domain.net;
rewrite ^(.*) https://www.domain.net$1 permanent;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/www.domain.net;
include other.conf;
#error_page 404 /404.html;
location ~ [^/]\.php(/|$)
{
# comment try_files $uri =404; to enable pathinfo
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
#include pathinfo.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
access_log /home/wwwlogs/www.domain.net.log access; }
它总是为我的域返回“重定向循环”错误,我尝试了许多不同的配置,但是我始终遇到同样的问题。 (我很欣赏我的SSL没有进行应有的配置,但仍然可以使用)
如果有人可以帮助我使它正常工作,我将不胜感激。
您需要将ssl配置放入服务器中:
监听443 SSL默认值;
ssl_certificate上的ssl <<将您的.crt >>;
ssl_certificate_key <<把您的.key >>;#强制https-redirects
如果($ scheme = http){返回301 https:// $ server_name $ request_uri; }
您是否将服务器上的文件放在端口443上监听?
因为如果您不配置nginx来监听端口443,则服务器将从80重定向到https。 从https到http(80)-这会导致循环。
要建立重定向,您仅需要以下步骤:
server {
listen 80 default;
server_name <<your domain>>;
return 301 https://<<your domain>>$request_uri;}
并使用与您在443 SSL上所做的配置相同的配置,但是要进行以下更改:
listen 443 ssl;
ssl_certificate <<your .crt>>;
ssl_certificate_key <<your .key>>;
ssl_client_certificate <<your client certificate .crt>>;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.