![nginx 和 PHP-FPM 的问题](https://linux22.com/image/686177/nginx%20%E5%92%8C%20PHP-FPM%20%E7%9A%84%E9%97%AE%E9%A2%98.png)
我无法让我的 Web 服务器 (nginx) 与 php-fpm 协同工作。页面一直在加载,然后加载时间到期。
我希望你们中有人能帮我解决这个问题。我导出了活动的 iptables 规则,希望能找到问题所在。
Chain INPUT (policy DROP 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
9962 1071K fail2ban-ssh tcp -- any any anywhere anywhere multiport dports ssh
0 0 ACCEPT all -- lo any anywhere anywhere
9982 1106K ACCEPT all -- any any anywhere anywhere state RELATED,ESTABLISHED
439 25076 ACCEPT tcp -- any any anywhere anywhere state NEW tcp dpt:ssh
117 5964 ACCEPT tcp -- any any anywhere anywhere state NEW tcp dpt:http
24 1372 ACCEPT tcp -- any any anywhere anywhere state NEW tcp dpt:ftp
15 620 ACCEPT tcp -- any any anywhere anywhere state NEW tcp dpts:20000:30000
88 4280 ACCEPT tcp -- any any anywhere anywhere state NEW tcp dpt:https
54 2438 ACCEPT icmp -- any any anywhere anywhere limit: avg 100/sec burst 100
0 0 ACCEPT icmp -- any any anywhere anywhere limit: avg 1/sec burst 10
2110 110K syn-flood tcp -- any any anywhere anywhere tcp flags:FIN,SYN,RST,ACK/SYN
2687 163K REJECT all -- any any anywhere anywhere reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 85 packets, 14451 bytes)
pkts bytes target prot opt in out source destination
Chain fail2ban-ssh (1 references)
pkts bytes target prot opt in out source destination
7951 908K RETURN all -- any any anywhere anywhere
Chain syn-flood (1 references)
pkts bytes target prot opt in out source destination
2110 110K RETURN tcp -- any any anywhere anywhere limit: avg 3/sec burst 6
0 0 REJECT all -- any any anywhere anywhere reject-with icmp-port-unreachable
更新
谢谢您的回复。它似乎不在我的 iptables 中。
server {
listen 80;
server_name <my domain>.<my tld>;
access_log /data/wwwlogs/<mydomain>.<mytld>_nginx.log combined;
index index.html index.htm index.php;
include /etc/nginx/conf/rewrite/none.conf;
root /data/wwwroot/<mydomain>.<mytld>;
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|ico)$ {
expires 30d;
access_log off;
}
location ~ .*\.(js|css)?$ {
expires 7d;
access_log off;
}
}
我需要说明的是,我对 iptables 完全没有经验,并且只是使用 Linux 的初学者。
答案1
如果没有亲自测试过,我无法确定,但这似乎只是一个将请求定向到 php-fpm 引擎的错误正则表达式行的情况。
location ~ [^/]\.php(/|$) {
仅匹配以“.php/”(不常见)结尾或明确以“.php”结尾的位置请求。我假设您使用了指南这里,这很好(尽管我以前从未见过有人这样做),但如果您不包含if
此处所示的语句,则可能会导致请求中断。还有一个问题可能会困扰您,如果您不设置类似
fastcgi_param SCRIPT_FILENAME /your/php/path/$fastcgi_script_name;
明确地(例如,使用 $document_root 隐式地fastcgi.conf
),您可能指向了错误的路径。
要记住的另外两件事是,您没有location /
块来处理未在根目录中明确找到的所有其他请求,最后您在顶部列出了您的 php 块,这是不正确的 - 它将首先尝试匹配以 php 结尾的 URI,而不是首先匹配和提供静态文件(jpg,ico 等),这通常是您想要的。