我正在使用 Linux Mint 17。我正在尝试使用 nginx 设置 PHP 7.1 或 PHP 7.2,但每当我访问 php 脚本时,我都会得到500 Internal Server Error
。每当我重新启动 nginx 或 PHP 时,我都不会收到任何错误。
以下是 的内容/etc/nginx/conf.d/default.conf
:
server {
listen 80;
listen [::]:80 default_server ipv6only=on; ## listen for ipv6
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
#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 /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
location ~ \.php$ {
proxy_pass http://127.0.0.1;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass unix:/var/run/php7.2-fpm.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
任何帮助都将不胜感激,因为我迫切需要让它工作起来。
编辑
worker_rlimit_nofile 100048
我通过添加并更改 worker_connections
为修复了 500 错误100048
。不幸的是,现在它显示“发生错误”,并且日志显示:
2018/02/11 21:53:23 [crit] 13219#13219: *1012 open() "/usr/share/nginx/html/50x.html" failed (24: Too many open files), client: 127.0.0.1, server: localhost, request: "GET /info.php HTTP/1.0", upstream: "http://127.0.0.1:80/info.php", host: "127.0.0.1"
2018/02/11 21:53:48 [crit] 13263#13263: *56464 connect() to 127.0.0.1:80 failed (99: Cannot assign requested address) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET /info.php HTTP/1.0", upstream: "http://127.0.0.1:80/info.php", host: "127.0.0.1"
答案1
我猜这和你提到的设置无关worker
。
另外,有两个位置也location ~ \.php$ {
没有意义。我从你的评论中看到,你已经删除了第一个位置:
location ~ \.php$ {
proxy_pass http://127.0.0.1;
}
好的。
现在找出为什么 PHP-fpm 无法正常工作:
PHP-fpm 是否已安装并正在运行?检查
service php7.2-fpm status
套接字文件去哪了?请在此处检查套接字配置文件中的设置
/etc/php/7.2/fpm/pool.d/
检查 PHP-fpm 是否使用具有应用程序文件夹权限的正确用户。
其他 nginx 配置问题:
添加
try_files
:location / { try_files $uri $uri/ /index.php?$args; }
root html;
从您的部分中删除该行location ~ \.php$ {
。不要将这两行放在一个
location
部分中。只需添加它们而不location / { }
添加任何内容:root /usr/share/nginx/html; index index.php index.html index.htm;