【问题标题】:nginx and php5-fpm works only with ip addressnginx 和 php5-fpm 仅适用于 ip 地址
【发布时间】:2014-09-27 19:08:16
【问题描述】:

我使用的是 Ubuntu 13,并且我已经安装了 nginx 和 php5-fpm;在此之前我安装了 PHP5 和 apache;我删除了

/etc/php5/fpm/pool.d/www.conf

user = www-data
group = www-data
listen = /var/run/php5-fpm.sock
listen.owner = www-data
listen.group = www-data
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
chdir = /

nginx 配置文件:

upstream php {
    server unix:/var/run/php5-fpm.socket;
}

server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;

root /usr/share/nginx/html;
index index.html index.htm index.php;

# Make site accessible from http://localhost/
server_name localhost;

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}


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

当我尝试时

http://local.host/info.php

它下载 info.php 文件而不是执行该文件

但是当我尝试时:

http://my.ip.address/info.php

它显示了phpinfo() 函数

问题出在哪里?

【问题讨论】:

标签: php nginx


【解决方案1】:

你可以试着改变你的配置:

server {
   listen 80;
   server_name localhost;

   root /usr/share/nginx/html;
   index index.html index.htm index.php;

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

}

还有你的 www.conf:

listen = localhost:9000
;listen = /var/run/php5-fpm.sock

【讨论】:

    【解决方案2】:

    换行到server_name localhost local.host 127.0.0.1;(你确定http://local(dot)host不是错字吗?)

    检查/etc/hostnames,如果它与上面不同,也添加它。还要检查您是否没有另一个条目 server{ ... } 监听相同的端口 80。

    查看文件夹/etc/nginx/sites-enabled/default文件名也包含server{...}参数。 http{...} 块位于 /etc/nginx/nginx.conf 中,有时可能包含 server{...} 块。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-05
      • 1970-01-01
      • 2014-02-28
      • 2016-06-28
      • 2016-02-24
      • 1970-01-01
      • 2021-07-30
      • 2016-12-26
      相关资源
      最近更新 更多