2016-02-26 54 views
0

我使用以下設置改變協議:問題與後301重定向(Nginx的/ BitrixVM/CentOS6.5)

s1.conf

# Default website 
server { 

    listen 80; 
    server_name test.com www.test.com; 
    return 301 https://test.com$request_uri; # enforce https 

    server_name_in_redirect off; 

    access_log /var/log/nginx/access.log main; 
    error_log /var/log/nginx/error.log warn; 

    proxy_set_header X-Real-IP  $remote_addr; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header Host $host:80; 
    proxy_set_header< X-Forwarded-Host $http_host 

    set $proxyserver "http://127.0.0.1:8888"; 
    set $docroot  "/home/bitrix/www"; 

    index index.php; 
    root /home/bitrix/www; 

    # Redirect to ssl if need 
    if (-f /home/bitrix/www/.htsecure) { rewrite ^(.*)$ https://$host$1 permanent; } 

    # Include parameters common to all websites 
    include bx/conf/bitrix.conf; 

    # Include server monitoring locations 
    include bx/server_monitor.conf; 
} 

s1_ssl.conf

# Default SSL certificate enabled website 
server { 
    listen 443 default_server ssl; 
    server_name test.com; 

    # Enable SSL connection 
    include bx/conf/ssl.conf; 
    server_name_in_redirect off; 

    proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header Host  $http_host:443; 
    proxy_set_header X-Forwarded-Host $http_host; 
    proxy_set_header X-Forwarded-Proto https; 

    proxy_set_header HTTPS  YES; 

    set $proxyserver "http://127.0.0.1:8888"; 
    set $docroot  "/home/bitrix/www"; 

    index index.php; 
    root /home/bitrix/www; 

    # Include parameters common to all websites 
    include bx/conf/bitrix.conf; 

    # Include server monitoring API's 
    include bx/server_monitor.conf; 

} 

當我嘗試鏈接http://test.com/xyz/https://test.com/xyz/一切正常。但是,當我嘗試像http://test.com/xyzhttps://test.com/xyz鏈接我得到 400錯誤的請求,清一色的HTTP請求發送到HTTPS端口

這嫋嫋輸出:

curl -I -k https://test.com/xyz 
HTTP/1.1 301 Moved Permanently 
Server: nginx/1.6.2 
Date: Mon, 22 Feb 2016 09:13:28 GMT 
Content-Type: text/html; charset=iso-8859-1 
Connection: keep-alive 
Location: http://test.com:443/xyz/ 
X-Content-Type-Options: nosniff 
X-Frame-Options: SAMEORIGIN 

爲什麼協議更改爲http?

回答

0

你忘了說http://test.com/xyz的引用是目錄。

什麼是邪惡的:mod_dir

A 「斜線」,當服務器收到一個URL http://servername/foo/dirname,其中目錄名是 目錄 請求重定向發出。目錄需要一個斜槓,所以mod_dir發出 重定向到http://servername/foo/dirname/

和他的 「HTTPS的」 不工作,方案https://開頭不是

應該做什麼:

1)nginx的配置不碰任何東西

2)在爲您的域名,例如httpd的配置: /etc/httpd/bx/conf/bx_ext_site.local.conf

哪裏串合作ntains命名您的服務器,例如: 服務器名site.local

由以下補充:https://開頭

是這樣: 服務器名稱https://site.local

這就是你需要

它沒有任何重定向

意味着問題是隱藏http://httpd.apache.org/docs/2.2/mod/core.html#servername

有時,服務器,其處理SSL設備後面運行手冊中,諸如 反向代理,負載平衡器或SSL卸載設備。如果是 ,請指定https://方案和 客戶端在ServerName僞指令中連接的端口號,以確保 服務器生成正確的自引用URL。