簡體   English   中英

Nginx將HTTP重寫為HTTPS表示重定向循環?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM