簡體   English   中英

nGinx和PHP-FPM下載index.php

[英]nGinx and PHP-FPM downloads index.php

我具有以下配置以偵聽端口80,但重定向到https。 然后,要通過index.php文件路由所有內容,但是,當我轉到頁面時,它只是下載index.php文件或在主頁上顯示403 forbidden

有任何想法嗎?

server {
    listen 80;
    server_name www.mydomain.com mydomain.com;
    rewrite ^ https://$server_name$request_uri? permanent;
}

server {
    listen 443;
    server_name www.mydomain.com;
    root /var/www/mydomain/public;

    ssl on;
    ssl_certificate mydomain.crt;
    ssl_certificate_key mydomain.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 / {
        if (!-e $request_filename){
            rewrite \.(jpeg|jpg|gif|png)$ /public/404.php break;
        }
        if (!-e $request_filename){
            rewrite ^(.*)$ /index.php break;
        }
    }

    location ~ \.php {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index /index.php;

        include /etc/nginx/fastcgi_params;

        fastcgi_split_path_info       ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO       $fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
        root /var/www/mydomain/public;
    }

    location ~ /\.ht {
        deny all;
    }
}

rewrite/break導致重寫的URI在相同的位置( location / )而非location ~ \\.php 請參閱重寫文檔。

location /塊看起來很奇怪,有兩個相同的if塊。

您可以考慮將其分為兩個塊:

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

location ~ \.(jpeg|jpg|gif|png)$ {
    try_files $uri /public/404.php;
}

如果/public/404.php是所有404錯誤的默認處理程序,則可以改用error_page指令:

error_page 404 /public/404.php;

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

location ~ \.(jpeg|jpg|gif|png)$ {
    try_files $uri =404;
}

有關更多信息,請參見locationtry_fileserror_page文檔。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM