2016-09-01 9 views
0

私はどんなユーザータイプでhttps://example.comへのすべてのトラフィックをリダイレクトしないようにしようとしています。すべてのトラフィックをhttpsにリダイレクトします。 nginxの

を次の.confファイルは非常に近いですが、それはhttp://example.com

あなたは私が変更すること何を示唆しているをキャッチしていませんすべてのトラフィックがhttps://example.comにリダイレクトされるようにするにはどうすればよいですか?

ありがとうございます。

server { 
    listen 80; 
    listen 443; 
    server_name www.example.com; 
    return 301 https://example.com$request_uri; 
} 

server { 
    server_name example.com; 
    access_log /var/log/nginx/example-access.log; 
    error_log /var/log/nginx/example-error.log; 
    root /var/www/html/web; 

    index index.html index.htm index.php; 

    location/{ 
     try_files $uri $uri/ /index.php$uri?$args; 
    } 

    rewrite ^/backend\.php/?(.*)$ /$1 permanent; 

    location /admin { 
     index admin content backend.php; 
     try_files $uri @rewriteapp; 
    } 

    location @rewriteapp { 
     rewrite ^(.*)$ /backend.php/$1 last; 
    } 

    location ~ "^(.+\.php)($|/)" { 
     fastcgi_split_path_info ^(.+\.php)(.*)$; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     fastcgi_param SCRIPT_NAME $fastcgi_script_name; 
     fastcgi_param PATH_INFO $fastcgi_path_info; 
     fastcgi_pass 127.0.0.1:9000; 
     include  fastcgi_params; 
    } 
} 

答えて

1

http://example.comの別のサーバーレコードを追加します。

server { 
    listen 80; 
    server_name example.com; 
    return 301 https://example.com$request_uri; 
} 

また、メインサーバ録画は専用ポート443でリッスンしていることを確認し、それにこれを追加します。

listen 443 ssl; 
+0

は、サイトを完全に削除します。重複するserver_nameがあると文句を言う – smugford

+0

申し訳ありませんが、サイトを完全にダウンさせています。 – smugford

+0

'sudo nginx -t'は何の出力ですか? – ollpu

0

使用個別のサーバー・ブロックを。

server { 
    listen 80; 
    server_name www.example.com 
       example.com; 
    return 301 https://example.com$request_uri; 
} 
server { 
    listen 443; 
    server_name www.example.com; 
    return 301 https://example.com$request_uri; 
} 
server { 
    server_name example.com; 
    access_log /var/log/nginx/example-access.log; 
    error_log /var/log/nginx/example-error.log; 
    root /var/www/html/web; 

    index index.html index.htm index.php; 

    location/{ 
     try_files $uri $uri/ /index.php$uri?$args; 
    } 

    rewrite ^/backend\.php/?(.*)$ /$1 permanent; 

    location /admin { 
     index admin content backend.php; 
     try_files $uri @rewriteapp; 
    } 

    location @rewriteapp { 
     rewrite ^(.*)$ /backend.php/$1 last; 
    } 

    location ~ "^(.+\.php)($|/)" { 
     fastcgi_split_path_info ^(.+\.php)(.*)$; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     fastcgi_param SCRIPT_NAME $fastcgi_script_name; 
     fastcgi_param PATH_INFO $fastcgi_path_info; 
     fastcgi_pass 127.0.0.1:9000; 
     include  fastcgi_params; 
    } 
} 
関連する問題