Nginx下载php而不是运行它

前端之家收集整理的这篇文章主要介绍了Nginx下载php而不是运行它前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我在linux REHL机器上设置了一个Nginx PHP服务器.
访问html文件一切顺利,但尝试访问PHP文件,该文件被下载,而不是被执行.

这是我的Nginx.conf:

  1. user Nginx;
  2. worker_processes 1;
  3. error_log /var/log/Nginx/error.log warn;
  4. pid /var/run/Nginx.pid;
  5. events {
  6. worker_connections 1024;
  7. }
  8. http {
  9. include /etc/Nginx/mime.types;
  10. default_type application/octet-stream;
  11. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  12. '$status $body_bytes_sent "$http_referer" '
  13. '"$http_user_agent" "$http_x_forwarded_for"';
  14. access_log /var/log/Nginx/access.log main;
  15. sendfile on;
  16. #tcp_nopush on;
  17. keepalive_timeout 65;
  18. #gzip on;
  19. include /etc/Nginx/conf.d/*.conf;
  20. }

…这是服务器块:

  1. server {
  2. listen 80;
  3. server_name {mywebsitename};
  4. #access_log logs/host.access.log main;
  5. location / {
  6. root /usr/share/Nginx/html/{mywebsitename}/;
  7. }
  8. location /ngx_status_2462 {
  9. stub_status on;
  10. access_log off;
  11. allow all;
  12. }
  13. location ~ \.PHP${
  14. # fastcgi_pass unix:/var/run/PHP5-fpm.sock;
  15. fastcgi_pass 127.0.0.1:9000;
  16. fastcgi_index index.PHP;
  17. fastcgi_param SCRIPT_FILENAME /usr/share/Nginx/html/{mywebsitename}$fastcgi_script_name;
  18. include fastcgi_params;
  19. }
  20. error_page 404 /404.html;
  21. location = /404.html {
  22. root /usr/share/Nginx/html;
  23. }
  24. error_page 500 502 503 504 /50x.html;
  25. location = /50x.html {
  26. root /usr/share/Nginx/html;
  27. }
  28. }
最佳答案
我只是有这个完全相同的问题.我正在使用Ubuntu 12.04和Linux Mint 14,所以不同的操作系统,但可能有同样的问题.

几个问题可能会发生.首先,您需要安装PHP5-fpm(FastCGI Process Manager).我试图用我的标准版本的PHP来运行它,但它不工作 – http://www.php.net/manual/en/install.fpm.php

我也安装了Apache,即使没有运行它也必须有一些冲突,因为一旦卸载了Apache,我就可以执行PHP文件了.

我也会看这条线

  1. fastcgi_pass 127.0.0.1:9000;

并考虑将其更改为

  1. fastcgi_pass unix:/var/run/PHP5-fpm.sock;

以下是为RHEL(和其他操作系统)安装NginxPHP5-FPM的详细指南

http://www.if-not-true-then-false.com/2011/install-nginx-php-fpm-on-fedora-centos-red-hat-rhel/

猜你在找的Nginx相关文章