2014-11-24 29 views
0

我有一個rails應用程序運行在說「myapp.com」。我試圖在「myapp.com/blog」加載wordpress。我開始了與nginx的配置看起來像這樣:nginx無法處理php的wordpress

server { 

    passenger_enabled on; 
    passenger_app_env staging; 

    server_name myapp.com; 

    root /home/deploy/myapp/current/public; 

    location /blog { 
    passenger_enabled off; 
    root /home/deploy/myapp/current/public; 
    index index.php index.html index.htm; 
    } 

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

,直到我想移動WordPress的目錄下的「博客」從<rails_root>/public//home/deploy/wordpress/blog這工作得很好。

要做到這一點,我的配置是這樣的。

server{ 
    location ^~ /blog{ 
    root /home/deploy/wordpress; 
    passenger_enabled off; 
    } 

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

    location/{ 
    passenger_enabled on; 
    root root /home/deploy/myapp/current/public; 
    passenger_app_env staging; 
    } 
} 

在此之後,而不是執行php,nginx開始下載php。任何人都可以提出或指出我可能出錯的地方嗎?

回答

0

刪除^~運營商,它應該工作。這是因爲它告訴nginx在位置塊選舉期間,下面的位置塊前綴必須優先於正則表達式塊位置(所以特別是php),並且它試圖從那裏提供php文件(所以作爲一個靜態文件並將它作爲application/octet-stream,因爲MIME類型可能是未知的)。

+0

你的答案幫助我找出解決方案。 – 2014-11-26 17:28:51