[英]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.