2016-02-13 60 views
1

我有以下配置在端口80上偵聽,但重定向到https。然後,通過index.php文件路由一切,但是,當我去一個頁面時,它只是下載index.php文件或在主頁上顯示403 forbiddennGinx和PHP-FPM下載index.php

任何想法?

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; 
    } 
} 
+0

服務關閉127.0.0.1:9000的文件是什麼? – Michael

+0

也嘗試刪除'fastcgi_index/index.php'中的''' – Michael

回答

0

rewrite/break使重寫的URI到在相同的位置(location /)而不是location ~ \.php進行處理。請參閱rewrite文檔。

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文檔以獲取更多信息。