
访问 php 文件会提示下载框,而不是执行这个文件,我的 nginx.conf 文件的配置如下: user www www; worker_processes auto;
error_log /data/wwwlogs/error_nginx.log crit; pid /var/run/nginx.pid; worker_rlimit_nofile 51200;
events { use epoll; worker_connections 51200; multi_accept on; }
http { include mime.types; default_type application/octet-stream; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 1024m; client_body_buffer_size 10m; sendfile on; tcp_nopush on; keepalive_timeout 120; server_tokens off; tcp_nodelay on;
fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; fastcgi_intercept_errors on;
#Gzip Compression gzip on; gzip_buffers 16 8k; gzip_comp_level 6; gzip_http_version 1.1; gzip_min_length 256; gzip_proxied any; gzip_vary on; gzip_types text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml text/Javascript application/Javascript application/x-Javascript text/x-json application/json application/x-web-app-manifest+json text/css text/plain text/x-component font/opentype application/x-font-ttf application/vnd.ms-fontobject image/x-icon; gzip_disable "MSIE [1-6].(?!.*SV1)";
#If you have a lot of static files to serve through Nginx then caching of the files' metadata (not the actual files' contents) can save some latency. open_file_cache max=1000 inactive=20s; open_file_cache_valid 30s; open_file_cache_min_uses 2; open_file_cache_errors on;
######################## default ############################ server { listen 80; server_name _; access_log /data/wwwlogs/access_nginx.log combined; root /data/wwwroot/default; index index.html index.htm index.php; #error_page 404 /404.html; #error_page 502 /502.html; location /nginx_status { stub_status on; access_log off; allow 127.0.0.1; deny all; } location ~ [^/].php(/|$) { #fastcgi_pass remote_php_ip:9000; fastcgi_pass unix:/dev/shm/php-cgi.sock; fastcgi_index index.php; include fastcgi.conf; } location ~ .*.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ { expires 30d; access_log off; } location ~ ..(js|css)?$ { expires 7d; access_log off; } location ~ /.ht { deny all; } } ########################## vhost ############################# include vhost/.conf; ########################## WAF ############################# lua_shared_dict limit 10m; lua_package_path "/usr/local/openresty/nginx/conf/waf/?.lua"; init_by_lua_file "/usr/local/openresty/nginx/conf/waf/init.lua"; access_by_lua_file "/usr/local/openresty/nginx/conf/waf/waf.lua"; }
1 des 2018-06-07 19:07:37 +08:00 via Android 这排版。。。没法看 |
2 xiri 2018-06-07 19:09:17 +08:00 via Android php-fpm 的配置文件改了吗 |
3 orangutan92 OP @xiri 照着网上的教程改了 n 次都不行。。 |
4 orangutan92 OP @des 我也不知道这编辑器为啥会这样,不支持 markdown 差评 |
5 to2false 2018-06-07 19:12:22 +08:00 via Android 这没眼看,太乱的排版了 |
6 orangutan92 OP ``` user www www; worker_processes auto; error_log /data/wwwlogs/error_nginx.log crit; pid /var/run/nginx.pid; worker_rlimit_nofile 51200; events { use epoll; worker_connections 51200; multi_accept on; } http { include mime.types; default_type application/octet-stream; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 1024m; client_body_buffer_size 10m; sendfile on; tcp_nopush on; keepalive_timeout 120; server_tokens off; tcp_nodelay on; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; fastcgi_intercept_errors on; #Gzip Compression gzip on; gzip_buffers 16 8k; gzip_comp_level 6; gzip_http_version 1.1; gzip_min_length 256; gzip_proxied any; gzip_vary on; gzip_types text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml text/Javascript application/Javascript application/x-Javascript text/x-json application/json application/x-web-app-manifest+json text/css text/plain text/x-component font/opentype application/x-font-ttf application/vnd.ms-fontobject image/x-icon; gzip_disable "MSIE [1-6]\.(?!.*SV1)"; #If you have a lot of static files to serve through Nginx then caching of the files' metadata (not the actual files' contents) can save some latency. open_file_cache max=1000 inactive=20s; open_file_cache_valid 30s; open_file_cache_min_uses 2; open_file_cache_errors on; ######################## default ############################ server { listen 80; server_name _; access_log /data/wwwlogs/access_nginx.log combined; root /data/wwwroot/default; index index.html index.htm index.php; #error_page 404 /404.html; #error_page 502 /502.html; location /nginx_status { stub_status on; access_log off; allow 127.0.0.1; deny all; } location ~ [^/]\.php(/|$) { #fastcgi_pass remote_php_ip:9000; fastcgi_pass 127.0.0.1:9000; #fastcgi_pass unix:/dev/shm/php-cgi.sock; fastcgi_index index.php; include fastcgi.conf; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ { expires 30d; access_log off; } location ~ .*\.(js|css)?$ { expires 7d; access_log off; } location ~ /\.ht { deny all; } } ########################## vhost ############################# include vhost/*.conf; ########################## WAF ############################# lua_shared_dict limit 10m; lua_package_path "/usr/local/openresty/nginx/conf/waf/?.lua"; init_by_lua_file "/usr/local/openresty/nginx/conf/waf/init.lua"; access_by_lua_file "/usr/local/openresty/nginx/conf/waf/waf.lua"; } ``` 试试 markdown,代码如上 |
7 xiri 2018-06-07 19:14:21 +08:00 via Android php-fpm 的配置文件里 8、10 行 user = nginx group = nginx 366-370 行,启用系统环境变量(把前面的;去掉) |
8 xiri 2018-06-07 19:15:13 +08:00 via Android @orangutan92 你改过这个吗 |
9 gclove 2018-06-07 19:16:38 +08:00 这种问题 ... 去 sf 上问啊 . 把 `location ~ [^/]\.php(/|$)` 改成 `location ~ \.php$` |
10 gclove 2018-06-07 19:20:02 +08:00 还有你作为一个初学者,怎么看这么 "复杂的" 配置教程 ... 明明对你来说 7 行的配置就够了 |
11 orangutan92 OP @xiri 没有改过,php-fpm 的配置文件用的是默认的 ``` [www] listen = /dev/shm/php-cgi.sock listen.backlog = -1 listen.allowed_clients = 127.0.0.1 listen.owner = www listen.group = www listen.mode = 0666 user = www group = www ``` |
12 orangutan92 OP @gclove 和 location 没关系吧,这个我没有动过的。核心的配置是: ``` location ~ [^/]\.php(/|$) { #fastcgi_pass remote_php_ip:9000; fastcgi_pass 127.0.0.1:9000; #fastcgi_pass unix:/dev/shm/php-cgi.sock; fastcgi_index index.php; include fastcgi.conf; } ``` |
13 xiri 2018-06-07 19:37:40 +08:00 via Android |
14 gclove 2018-06-07 19:39:55 +08:00 我意思是让你把这里改成我这个. 我看了确实没有问题啊,你重启 nginx 了吗 ? 除非你那几个 lua 文件有问题. |
15 orangutan92 OP @xiri 我用的是 oneinstack 一键安装的,基本的配置和报错我都解决了,现在就卡在这里。。。 |
16 gclove 2018-06-07 19:41:07 +08:00 还有一种可能是,你访问的域名并没有访问到这个 `server {}`, 而是到了 `vhost/*.conf` 里面的配置 |
17 xiri 2018-06-07 19:43:04 +08:00 via Android @orangutan92 oneinstack 不是有添加虚拟主机的脚本吗?为啥还要自己改 |
18 orangutan92 OP @gclove 重启了的,域名访问 html 和 txt 图片什么的都是正常的,就 php 不行。。。 |
20 gclove 2018-06-07 19:44:48 +08:00 看我签名的回复,照我说的检查 @orangutan92 |
21 orangutan92 OP @gclove 改成 `location ~ \.php$`还是不行 |
22 Track3 2018-06-07 19:56:50 +08:00 via Android 貌似你的 php-fpm 用的是 unix socket,不是 tcp。把 nginx 配置文件中`fastcgi_pass 127.0.0.1:9000; `这一行注释,换成下面的`fastcgi_pass unix:/dev/shm/php-cgi.sock; `试试 |
23 orangutan92 OP @gclove vhost 里面的配置很简单呐,就是域名和路径 |
24 orangutan92 OP @Track3 之前用的就是那个.sock 文件,还是有问题。这个文件在我重启了 fpm 后变成空的了 |
25 Track3 2018-06-07 20:04:47 +08:00 via Android 那个文件有权限吗?把所有者改成 www 试试,如果还是不行,干脆把 php-fpm 配置改成 listen = 127.0.0.1:9000,反正这个地址跟 nginx 配置是必须对应的 |
26 dototototo 2018-06-07 20:24:20 +08:00 via Android 你用别的浏览器试试是否还存在这个问题? include mime.types; default_type application/octet-stream; 可以试着从这两行里面找找原因。 |
27 gclove 2018-06-07 20:29:06 +08:00 |
28 gclove 2018-06-07 20:32:15 +08:00 不管怎么样,nginx 配置了 fastcgi_pass 是不会把源文件发过去的. 能发过去的只有 cgi。 上面打错了 |
29 orangutan92 OP @Track3 listen 试过了不行呢 |
30 orangutan92 OP @dototototo 好,我明天试试 |
31 1762628386 2018-06-07 20:51:32 +08:00 没走到 php 下面的问题看看吧 #fastcgi_pass remote_php_ip:9000; fastcgi_pass 127.0.0.1:9000; #fastcgi_pass unix:/dev/shm/php-cgi.sock; fastcgi_index index.php; include fastcgi.conf; |
32 orangutan92 OP @1762628386 这个配置有什么问题呢? |
33 orangutan92 OP @dototototo 刚刚试过了,火狐也不行 |
34 jasonhzy 2018-06-08 09:45:27 +08:00 @orangutan92 注意这个设置 default_type application/octet-stream, 可以改成 default_type text/html |
35 wqsfree 2018-06-08 10:03:31 +08:00 兄弟下面是我的配置,你自己看看对一下,不行你就自己复制我这个粘贴过,修改下对应的路径 nginx 配置文件 user nobody nobody; worker_processes 2; error_log /usr/local/nginx/logs/nginx_error.log crit; pid /usr/local/nginx/logs/nginx.pid; worker_rlimit_nofile 51200; events { use epoll; worker_connections 6000; } http { include mime.types; default_type application/octet-stream; server_names_hash_bucket_size 3526; server_names_hash_max_size 4096; log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]' '$host "$request_uri" $status' '"$http_referer" "$http_user_agent"'; sendfile on; tcp_nopush on; keepalive_timeout 30; client_header_timeout 3m; client_body_timeout 3m; send_timeout 3m; connection_pool_size 256; client_header_buffer_size 1k; large_client_header_buffers 8 4k; request_pool_size 4k; output_buffers 4 32k; postpone_output 1460; client_max_body_size 10m; client_body_buffer_size 256k; client_body_temp_path /usr/local/nginx/client_body_temp; proxy_temp_path /usr/local/nginx/proxy_temp; fastcgi_temp_path /usr/local/nginx/fastcgi_temp; fastcgi_intercept_errors on; tcp_nodelay on; gzip on; gzip_min_length 1k; gzip_buffers 4 8k; gzip_comp_level 5; gzip_http_version 1.1; gzip_types text/plain application/x-Javascript text/css text/htm application/xml; server { listen 80; server_name localhost; index index.html index.htm index.php; root /usr/local/nginx/html; location ~ \.php$ { include fastcgi_params; fastcgi_pass unix:/tmp/php-fcgi.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name; } } } 这下面的是 PHP 配置文件 [global] pid = /usr/local/php/var/run/php-fpm.pid error_log = /usr/local/php/var/log/php-fpm.log [www] listen = /tmp/php-fcgi.sock user = php-fpm group = php-fpm listen.owner = nobody //和上面的 nginx 的一致 listen.group = nobody // 同上 pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 rlimit_files = 1024 |
36 wqsfree 2018-06-08 10:05:29 +08:00 最好的方法是看看你的错误日志,报的是什么错误,这个很好解决的。你这个配置文件看的我头疼 |
37 yesono 2018-06-08 13:48:31 +08:00 默认 OneninStack nginx 连接 PHP 是走 /dev/shm/php-cgi.sock 你非要改成走端口,9000 端口没起来.... ` fastcgi_pass 127.0.0.1:9000; #fastcgi_pass unix:/dev/shm/php-cgi.sock; ` |
38 orangutan92 OP @wqsfree user 为啥是 nobody 啊,Nginx 没有错误日志看不了吧,下载不算 error 的。 |
39 orangutan92 OP @yesono 最开始的时候用的就是这个 sock,要是有用我就不改了。。。 |
40 wqsfree 2018-06-08 15:34:27 +08:00 @orangutan92 自定义一个用户跑 nginx 服务,这个用户你自己随便设置,要不你给 root 权限给我,我帮你弄吧,我看你挺费劲的 |
41 orangutan92 OP @wqsfree 好,留个你的 QQ 吧~ |
42 wqsfree 2018-06-08 16:37:49 +08:00 @orangutan92 771009669 |
43 orangutan92 OP @wqsfree 感谢这位兄弟帮我解决了问题,我可以把你修改的配置贴出来吗?方便以后遇到同样问题的人~ |
44 wqsfree 2018-06-12 17:10:03 +08:00 @orangutan92 可以,但是我想把我留下的 QQ 号码删除了,怎么才能联系到站长把我留下的 QQ 号码删了呢? |
45 orangutan92 OP 其实就是把 vhost 里面的虚拟主机配置文件重写一下,把 nginx.conf 的 server 配置粘贴过来,原来的参数还是加上。 |