打开网页,php源码暴露,nginx配置文件如下
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
1
hobbyliu OP 可以确定,PHP-FPM 监听9000 端口正常
[root@localhost ~]# netstat -npa | grep 9000 tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 2142/php-fpm: maste |
2
endoffight 2015-05-27 14:44:20 +08:00
加一条root 指向根目录试试
|
3
hobbyliu OP @endoffight 加了 无效
location ~ \.php$ { |~ root /home/hobby/service; |~ fastcgi_pass 127.0.0.1:9000; |~ fastcgi_index index.php; |~ fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; |~ include fastcgi_params; |~ } |
4
xjx0524 2015-05-27 14:50:20 +08:00
把$document_root改成/home/hobby/service试试
|
5
shiny 2015-05-27 14:52:56 +08:00
nginx 配置没走到这个 location 吧。走到这个 location 如果有问题就是 50x 错误。 建议贴全 nginx 配置
|
6
hobbyliu OP @shiny
``` #user nginx; worker_processes 1; error_log /var/log/nginx/error.log; #error_log /var/log/nginx/error.log notice; #error_log /var/log/nginx/error.log info; pid /run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; index index.html index.htm; ############################## server { listen 80; server_name lumentest; root /home/hobby/service; #root /usr/share/nginx/html; index index.html index.htm; #charset koi8-r; #access_log logs/host.access.log main; #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} |
8
endoffight 2015-05-27 15:09:53 +08:00
location ~ .*\.(php|php5){
45 fastcgi_pass 127.0.0.1:9000; 46 fastcgi_index index.php; 47 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 48 include fastcgi_params; 你改成我这个正则试试 |
9
fangjinmin 2015-05-27 15:31:08 +08:00
很明显是php文件没有当作PHP解析。
按照下面的步骤看一下, 1,php-fpm的配置文件,看一下php-fpm的运行的user和group是否设置正确。 2,重启php-fpm和nginx |
10
userlogin 2015-05-27 15:37:38 +08:00
将:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 改成: fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name; reload nginx. |
11
userlogin 2015-05-27 15:40:52 +08:00
ps. 如上条,如nginx根目录非/usr/share/nginx/html,请根据实际情况更换为nginx的根目录路径。
|
12
Havee 2015-05-27 16:13:18 +08:00
php-fpm 配置中的权限是否跟你 /home/hobby/service 的权限一致
|
13
huigeer 2015-05-27 16:24:32 +08:00
看看nginx的error_log
|
14
hzqim 2015-05-27 17:11:02 +08:00
空白页吧?
来来来 location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi.conf; } 修改一下include fastcgi.conf; |