Nginx:HTTPS経由で画像が提供されない

Nginx:HTTPS経由で画像が提供されない

admin/私のサイトにHTTPSに含めたいサブディレクトリがあるので、次のように次の設定を試しました。これ:

server {
    listen 80;

    server_name blob.tld;
    root /srv/www/blob;
    index index.php index.html index.htm;

    location /blog/admin/* {
        return 301 https://$server_name$request_uri;
    }

    location / {
        try_files $uri $uri/ $uri/index.php /index.html;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi_params;
    }
}

server {
    listen 443 ssl;
    server_name blob.tld;

    root /srv/www/blob/;
    index index.php index.html index.htm;

    ssl_certificate /srv/www/blob.tld.pem;
    ssl_certificate_key /srv/www/blob.tld.key;

    ssl_session_timeout 5m;

    ssl_protocols SSLv3 TLSv1;
    ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;
    ssl_prefer_server_ciphers on;

    location /blog/admin {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        try_files $uri $uri/index.php /index.html;
    }

    location / {
        return 301 http://$server_name$request_uri;
    }
}

admin/style/しかし、画像は提供されません。

ログファイルを確認すると、次のようになります。

/var/log/nginx/access.log:
127.0.0.1 - - [25/Apr/2014:15:06:27 +0200] "GET /blog/admin/style/lock.png HTTP/1.1" 403 46 "-" "Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit (KHTML, like Gecko) Chrome/32.0"

/var/log/nginx/error.log:
2014/04/25 15:06:27 [error] 23629#0: *404 FastCGI sent in stderr: "Access to the script '/srv/www/blob/blog/admin/style/lock.png' has been denied (see security.limit_extensions)" while reading response header from upstream, client: 127.0.0.1, server: blob.tld, request: "GET /blog/admin/style/lock.png HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000"

error.logファイルを見ると、問題はHTTPSサーバーの最初の場所ディレクティブで発生したようです(HTTPとの違いはです~ \.php$)。だから正しい対称性を作ろうとします。\.php$他のディレクティブlocation内のディレクティブを含む):

server {
    listen 443 ssl;
    [...]

    location /blog/admin/* {
        try_files $uri $uri/ $uri/index.php /index.html;
    }

    location / {
        return 301 http://$server_name$request_uri;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi_params;
    }
}

しかし... HTTPSはまったくありません。

画像をHTTPとして提供する方法はまだ残っていますが、少し残念です。

location  /blog/admin/style {
    return 301 http://$server_name$request_uri;
}

私はnginx 1.1.19とphp 5.3.10とphp-fpmを持っています。

ベストアンサー1

https部分を送信するのはなぜですか?すべて/blog/adminの下のFastCGIに移動しますか? http部分のように*.phpに対して特別なルールを作成してみてはいかがでしょうか?

つまり、httpの下には次のものがあります。

location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    include fastcgi_params;
}

しかし、httpsの下には次のものがあります。

location /blog/admin {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    include fastcgi_params;
    try_files $uri $uri/index.php /index.html;
}

私の考えでは、あなたが変わったら/ブログ/管理者到着~/ブログ/管理者/.*\.php$あなたの問題は解決されます...

おすすめ記事