server { listen 8080; server_name localhost; root /usr/local/nginx/html;
#charset koi8-r;
#access_log logs/host.access.log main;
location ~ \.php$ {
root /usr/local/nginx/html;
fastcgi_pass 127.0.0.0:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location / {
root /usr/local/nginx/html
index index.php
}
1
zhanglintc 2019-05-20 14:25:51 +08:00
fastcgi_pass 可能需要改成这个样子:
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; 那个 .sock 文件的具体地址你可能需要根据你自己的版本稍作修改. |
2
lazyyz 2019-05-20 14:39:08 +08:00 via Android
1 楼正解
|
3
dapengzhao OP @zhanglintc
[root@ecs-68ac ~]# find / -name '*sock' /usr/sbin/mksock 我系统下没有.sock 文件 在 www.config 中 listion 监听的就是 127.0.0.1:9000 |
4
dapengzhao OP @lazyyz
[root@ecs-68ac ~]# find / -name '*sock' /usr/sbin/mksock 我系统下没有.sock 文件 在 www.config 中 listion 监听的就是 127.0.0.1:9000 |
5
sheeta 2019-05-20 15:05:18 +08:00
@dapengzhao 你配置文件中是 127.0.0.0:9000
|
6
poisedflw 2019-05-20 15:14:40 +08:00
location ~ \.php$ {
try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } 重启 nginx、重启 fpm。清浏览器缓存 |
7
dapengzhao OP @sheeta
server { listen 8080; server_name localhost; root /usr/local/nginx/html; #charset koi8-r; #access_log logs/host.access.log main; location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location / { root /usr/local/nginx/html index index.php } location ~ \.php$ 里面的 root 我用 /usr/local/nginx/html 和 html 都试过结果还是下载。。。。。 |
8
dapengzhao OP @poisedflw 重启了 nginx 没有重启 fpm 我再试一下
|
9
dapengzhao OP |
10
frozenway 2019-05-20 15:31:56 +08:00
估计是 SCRIPT_FILENAME 没写对,再或者是 9000 端口没有开启
|
11
dapengzhao OP @frozenway SCRIPT_FILENAME 没写对是啥意思?
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 18157/php-fpm tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 18180/nginx |
12
keepeye 2019-05-20 15:39:01 +08:00
location ~ \.php$ {
return 403; } 先看看有没有走到这个块里面 |
13
dapengzhao OP @keepeye 好像没有,还是直接去下载了
|
14
dapengzhao OP @keepeye
worker_processes 1; events { worker_connections 1024; } http { include mime.types; sendfile on; keepalive_timeout 65; server { listen 8080; server_name 114.116.109.253; root /usr/local/nginx/html; #location ~ \.php$ { #try_files $uri =404; #fastcgi_split_path_info ^(.+\.php)(/.+)$; #fastcgi_pass 127.0.0.1:9000; #fastcgi_index index.php; #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #include fastcgi_params; #} location ~ \.php$ { return 403; } location / { root /usr/local/nginx/html index index.php } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } } |
15
LittleLease 2019-05-20 16:06:01 +08:00
执行 ps -ef | grep php 看看你的 php-fpm 进程有没有
|
16
liangzi 2019-05-20 16:07:40 +08:00 via Android
ng 不支持 PHP 的配置了 先保证 php-fpm 能运行起来再改 ng
|
17
dapengzhao OP @LittleLease 有,现在问题是 nginx 解析完第一个 location 之后,不匹配下面的 location 了
|
18
dapengzhao OP @liangzi
root 18157 1 0 15:24 ? 00:00:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf) www-data 18158 18157 0 15:24 ? 00:00:00 php-fpm: pool www www-data 18159 18157 0 15:24 ? 00:00:00 php-fpm: pool www www-data 18160 18157 0 15:24 ? 00:00:00 php-fpm: pool www www-data 18161 18157 0 15:24 ? 00:00:00 php-fpm: pool www www-data 18162 18157 0 15:24 ? 00:00:00 php-fpm: pool www root 18259 17754 0 16:06 pts/0 00:00:00 grep php |
19
ochatokori 2019-05-20 16:11:20 +08:00 via Android
直接下载文件我感觉是 nginx 的 mime type 出问题了
|
20
sheeta 2019-05-20 16:12:45 +08:00
location / {
root /usr/local/nginx/html index index.php location ~ \.php$ { root /usr/local/nginx/html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } @dapengzhao 试试这样 |
21
dapengzhao OP @ochatokori mime type 是跟 css 静态文件一类的资源有关系吧
|
22
dapengzhao OP @sheeta 还是在下载 index.php
|
23
uTOmOuk3L6sb4MSI 2019-05-20 16:28:08 +08:00
https://nginxconfig.io/
站长好像发过这个,看你需要否 |
24
poisedflw 2019-05-20 16:29:09 +08:00
强烈怀疑你 nginx 有错误日志。
你先检查下 nginx 是否有错误日志(就是没重启成功) 然后单独测试下 fpm 是否 ok |
25
lazyyz 2019-05-20 16:58:49 +08:00 via Android
直接下载 php 一般是 Nginx 没有配置正确,给你一段最简单的试试,sock 文件会自动生成的,下面的 7.3 改成你的 php 版本
server { listen 80 default_server; root /usr/local/nginx/html; index index.html index.php; server_name _; # pass PHP scripts to FastCGI server # location ~ \.php$ { include snippets/fastcgi-php.conf; # # With php-fpm (or other unix sockets): fastcgi_pass unix:/run/php/php7.3-fpm.sock; } } |
26
lazyyz 2019-05-20 17:00:16 +08:00 via Android
@dapengzhao 127.0.0.1:9000 用的 php cgi 模式,socks 是 php-fpm
|
27
liwl 2019-05-20 17:26:10 +08:00
location ~ .*\.php(\/.*)*$
{ try_files $uri =404; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi_params.conf; fastcgi_param SCRIPT_FILENAME $document_root$real_script_name; fastcgi_param SCRIPT_NAME $real_script_name; fastcgi_param PATH_INFO $path_info; } |
28
dapengzhao OP @liwl
server { listen 8080; server_name 114.116.109.253; root /usr/local/nginx/html; location ~ .*\.php(\/.*)*$ { try_files $uri =404; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi_params.conf; fastcgi_param SCRIPT_FILENAME $document_root$real_script_name; fastcgi_param SCRIPT_NAME $real_script_name; fastcgi_param PATH_INFO $path_info; } } 还是不行,直接下载了 |
29
ddsfeng 2019-05-20 19:25:19 +08:00 1
@dapengzhao 好了, 不谢.
|
30
falcon05 2019-05-20 19:35:37 +08:00 via iPhone
估计是 mine-type 或者 Server name 的问题,压根没进入这个 Server,如果是 php-fpm 的问题会是 502,根本不会有下载。
|
31
zhanglintc 2019-05-20 20:55:26 +08:00
@ddsfeng #29 改了啥地方啊
|
32
Takamine 2019-05-20 22:03:53 +08:00
我记得我之前遇到的时候是把.php 文件没有配置解析的问题。
|
33
liangzi 2019-05-20 22:13:36 +08:00 via Android
卧槽还没弄好呢?
|
34
liangzi 2019-05-20 22:29:41 +08:00
### 原因
- 当 nginx 不配置支持 php 模块时,当你访问 php 文件时候,浏览器默认下载 php 文件,而不是执行 php - 排查你的 php-XXX 之类的扩展 是不是有少安装了什么插件 - 配置 php-fpm.conf openSUSE 搭建 wordpress 为例 ` sudo cp /etc/php7/fpm/php-fpm.conf.default /etc/php7/fpm/php-fpm.conf` `sudo cp /etc/php7/fpm/php-fpm.d/www.conf.default /etc/php7/fpm/php-fpm.d/wordpress.conf` cat /etc/php7/fpm/php-fpm.conf ``` pid = run/php-fpm.pid include=/etc/php7/fpm/php-fpm.d/*.conf ``` cat /etc/php7/fpm/php-fpm.d/wordpress.conf ``` user = 你的用户名 group = users listen = 127.0.0.1:9000 pm = dynamic ``` nginx -t sudo php-fpm -t sudo php-fpm sudo systemctl start nginx.service ### nginx ``` server { listen 80; root /这里改你的具体位置; index index.php index.html index.htm; server_name 你的主机名 client_max_body_size 100M; location / { try_files $uri $uri/ /index.php?$args; } 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; } } `` |
35
dapengzhao OP @ddsfeng 大哥🙏,能不能说下改了啥地方
|