簡體   English   中英

nginx和php5-fpm僅適用於IP地址

[英]nginx and php5-fpm works only with ip address

我正在使用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()函數

問題出在哪兒 ?

您可以嘗試更改配置:

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

將行更改為server_name localhost local.host 127.0.0.1; (您確定http://local(dot)host不是拼寫錯誤嗎?)

檢查/etc/hostnames ,如果與上面的名稱不同,也將其添加。 還要檢查您是否沒有另一個監聽相同端口80的入口server{ ... }入口。

檢查文件夾/etc/nginx/sites-enabled/default文件名還包含server{...}參數。 http{...}塊位於/etc/nginx/nginx.conf ,有時可能包含server{...}塊。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM