2017-01-02 15 views
0

を使用している場合、サーバーは404を表示します。https [nginx]

私はletsencryptからSSL証明書を受け取りました。自分のサーバーにHTTPとHTTPSの両方をサポートしようとしています。証明書は良いですが、httpsを使用して自分のサイトにアクセスしようとすると404が表示されます。ここに私の設定ファイルがあります:

server { 
    server_name my.domain.org; 

    root /var/www/my.domain.org/htdocs; 
    index index.php index.html index.html; 

    server_name my.domain.org; 
    location/{ 
    try_files $uri $uri/ /index.php?$args; 
    } 

    # Add trailing slash to */wp-admin requests. 
    rewrite /wp-admin$ $scheme://$host$uri/ permanent; 

    location ~ \.php$ { 
    fastcgi_split_path_info ^(.+\.php)(/.+)$; 
    # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini 

    # # With php5-cgi alone: 
    # fastcgi_pass 127.0.0.1:9000; 
    # With php5-fpm: 
    fastcgi_pass unix:/var/run/php5-fpm.sock; 
    fastcgi_index index.php; 
    include fastcgi_params; 
    } 

    location = /favicon.ico { 
    access_log off; 
    log_not_found off; 
    } 

    location = /robots.txt { 
    access_log off; 
    log_not_found off; 
    } 

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { 
    expires max; 
    log_not_found off; 
    } 
} 

server { 
    listen 443; 

    ssl on; 
    ssl_certificate /etc/letsencrypt/live/my.domain.org/fullchain.pem; 
    ssl_certificate_key /etc/letsencrypt/live/my.domain.org/privkey.pem; 

    server_name my.domain.org; 
    access_log /var/log/nginx/nginx.vhost.access.log; 
    error_log /var/log/nginx/nginx.vhost.error.log; 

    location/{ 
    root /var/www/my.domain.org/htdocs; 
    index index.php index.html index.html; 
    } 
} 

答えて

0

httpsの設定はhttpと同じではありません。

だから、ちょうど同じHTTP設定をコピーし、SSL特定の部分を追加します。

# https 
server { 
    listen 443 ssl; 
    # for http2 support uncomment line bellow and comment line above 
    # listen 443 ssl http2; 

    ssl on; 
    ssl_certificate /etc/letsencrypt/live/my.domain.org/fullchain.pem; 
    ssl_certificate_key /etc/letsencrypt/live/my.domain.org/privkey.pem; 

    server_name my.domain.org; 

    root /var/www/my.domain.org/htdocs; 
    index index.php index.html index.html; 

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

    rewrite /wp-admin$ $scheme://$host$uri/ permanent; 

    location ~ \.php$ { 
    fastcgi_split_path_info ^(.+\.php)(/.+)$; 
    fastcgi_pass unix:/var/run/php5-fpm.sock; 
    fastcgi_index index.php; 
    include fastcgi_params; 
    } 

    location = /favicon.ico { 
    access_log off; 
    log_not_found off; 
    } 

    location = /robots.txt { 
    access_log off; 
    log_not_found off; 
    } 

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { 
    expires max; 
    log_not_found off; 
    } 
} 

#http 
server { 
    listen 80; 
    root /var/www/my.domain.org/htdocs; 
    index index.php index.html index.html; 

    server_name my.domain.org; 
    location/{ 
    try_files $uri $uri/ /index.php?$args; 
    } 

    rewrite /wp-admin$ $scheme://$host$uri/ permanent; 

    location ~ \.php$ { 
    fastcgi_split_path_info ^(.+\.php)(/.+)$; 
    fastcgi_pass unix:/var/run/php5-fpm.sock; 
    fastcgi_index index.php; 
    include fastcgi_params; 
    } 

    location = /favicon.ico { 
    access_log off; 
    log_not_found off; 
    } 

    location = /robots.txt { 
    access_log off; 
    log_not_found off; 
    } 

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { 
    expires max; 
    log_not_found off; 
    } 
} 
+0

は、私はこれを感謝、ありがとうございます。明確化のためのもう1つの質問、あなたがここに貼り付けたものは私の全体の設定ファイルでしょうか? (他のサーバー{}ブロックを省略して)これは単に私が今SSL用に持っているブロックを置き換えるだけでしょうか? – nginthrowaway

+0

@ginthrowaway私は私の答えを更新しましたあなたはすべてコピーすることができます – num8er

+1

魅力のように働いた、ありがとう! – nginthrowaway

関連する問題