[英]nginx serves some (but not all) php files as downloads
我正在運行nginx的Ubuntu服務器上安裝Wordpress。 安裝過程非常順利( 安裝LEMP和安裝Wordpress教程之后 - 帶我通過mysql,php5-fpm和wordpress設置),似乎主要工作。 我可以查看Wordpress管理頁面,創建博客帖子甚至查看這些帖子。 但是當我嘗試訪問我博客的主頁(例如index.php)時,nginx將該文件作為下載而不是執行它來提供。 我已經嘗試過Nginx中的配置服務.php文件作為下載,而不是執行它們無濟於事。
這是我的虛擬服務器文件:
server {
listen 80;
server_name my.domain.com;
root /my/wordpress/home/dir;
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;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location / {
try_files $uri $uri/ /index.php?$args;
rewrite ^/([_0-9a-zA-Z-]+/)?wp-admin$ /$1wp-admin/ redirect;
if (-e $request_filename) {
rewrite ^/([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) /$2 break;
}
rewrite ^/([_0-9a-zA-Z-]+/)?(.*\.php)$ /$2 break;
rewrite ^(.*)$ /index.php break;
}
}
和nginx.conf:
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
為清楚起見,我刪除了注釋行。 sudo nginx -t
報告沒有錯誤。
如何讓index.php執行而不是作為下載? 謝謝你的幫助。
編輯:看起來這是一個瀏覽器緩存問題。 我嘗試刪除過去24小時內的緩存數據,但它沒有改變任何內容。 刪除所有內容后,它現在正確加載而不是下載。 它也可以加載到其他瀏覽器/計算機上。
對於在Nginx后面運行Wordpress,這對我有用:
location / {
# try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location /wp-content/updraft {
deny all;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
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-Nginx項目中查看示例文件。 特別是,您可能還對globals / restrictions.conf文件感興趣,這會使您的安裝變得有些困難。 如果你在同一台服務器上有幾個Wordpress站點,他們都可以共享這些“全局”配置文件,讓你的Wordpress管理員生活更輕松。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.