2013-11-15 23 views
1

我的任務是完成一個項目。 我們有我們的服務器上的兩個目錄,一個是 http://example.com/app ,另一個是 http://example.com/fwNGINX http to https如果只包含某個目錄

我被要求做的,是從HTTP重定向到HTTPS,如果在這兩個目錄頁面上的任何訪問者的土地(應用程序和FW) 這是我在配置文件中迄今爲止所做的。當我將這些行添加到「服務器」下面的配置文件並重新啓動時,該站點不會恢復。不幸的是,我無法訪問日誌文件。欣賞任何人都願意看看這

location ~ ^/miner/memclub/.+\.html$ { 
    rewrite ^(.+)\.html$ /bootstrap.php?file=$1.html last; 
    rewrite ^(.+)\.phtml$ /bootstrap.php?file=$1.phtml last; 
    error_page 404 = /404.php; 
} 

server { 
server_name site.org; 
server_name *.site.org; 
location /app { 
    if ($scheme = http) { 
    rewrite^https://site.org/app last; 
    } 
    } 
} 

回答

3

首先我不認爲你可以有2 server_name,這兩條線合併爲一條線

server_name example.com *.example.com; 

並做HTTPS重定向我會建議使用2臺獨立的服務器,您需要一個監聽端口443反正

server { 
    server_name example.com www.example.com; # which ever you are using 
    listen 443 ssl; 
    location/{ 
     # all your https configuration 
    } 
} 
server { 
    server_name example.com www.example.com: 
    listen 80; 
    location /app { 
     return 301 https://$http_host$request_uri; 
    } 
    location /fw { 
     return 301 https://$http_host$request_uri; 
    } 
    location/{ 
     # the rest of the non https configuration 
    } 
} 

我知道你可以合併兩個appfw到一個位置,但我相信這樣做沒有正則表達式更快,如果你想這樣做它反正在這裏它是

location /(app|fw) { 
    return 301 https://$http_host$request_uri; 
}