![PHP-FPM + PHP-5.2.14 + NGINX-出现 404](https://linux22.com/image/527369/PHP-FPM%20%2B%20PHP-5.2.14%20%2B%20NGINX-%E5%87%BA%E7%8E%B0%20404.png)
我一直在努力尝试通过 PHP-FPM 让 PHP 运行。我们的一台服务器受到 slowloris 的影响,因为 apache 无法处理它。
我让 NGINX 运行良好,并将数据传回 Apache,但现在我试图至少在大多数情况下使用纯 NGINX。我从源代码安装了 PHP-5.2.14,并使用 PHP-FPM 为 5.14 打补丁,并配置了 ff:
'./configure' '-enable-fastcgi' '--enable-fpm' '--build=x86_64-redhat-linux-gnu' '--host=x86_64-redhat-linux-gnu' '--target=x86_64-redhat-linux-gnu' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib64' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/usr/com' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--cache-file=../config.cache' '--with-libdir=lib64' '--with-config-file-path=/etc' '--with-config-file-scan-dir=/etc/php.d' '--disable-debug' '--with-pic' '--disable-rpath' '--with-pear=/usr/share/pear' '--with-bz2' '--with-curl' '--with-exec-dir=/usr/bin' '--with-freetype-dir=/usr' '--with-png-dir=/usr' '--enable-gd-native-ttf' '--without-gdbm' '--with-gettext' '--with-gmp' '--with-iconv' '--with-jpeg-dir=/usr' '--with-openssl' '--with-png' '--with-pspell' '--with-expat-dir=/usr' '--with-zlib' '--with-zlib-dir=/usr/include' '--with-layout=GNU' '--enable-exif' '--enable-ftp' '--enable-magic-quotes' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-sysvmsg' '--enable-track-vars' '--enable-trans-sid' '--enable-yp' '--enable-wddx' '--with-kerberos' '--enable-ucd-snmp-hack' '--with-unixODBC=shared,/usr' '--enable-memory-limit' '--enable-shmop' '--enable-calendar' '--enable-dbx' '--enable-dio' '--with-mime-magic=/etc/httpd/conf/magic' '--without-sqlite' '--with-libxml-dir=/usr' '--with-xml' '--without-tidy' '--with-mhash=shared,/usr' '--with-mcrypt=shared,/usr' '--without-mssql' '--without-oci8' '--without-mysql' '--without-gd' '--without-odbc' '--disable-dom' '--disable-dba' '--without-unixODBC' '--disable-pdo' '--disable-xmlreader' '--disable-xmlwriter' '--disable-json'
运行 php-fpm 并正确设置配置以监听 127.0.0.1:9000 ,使用用户 apache ,因为我的大多数目录都分组到这个用户中
我对 NGINX 有以下 fastcgi 配置:
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param REDIRECT_STATUS 200;
和我的 NGINX 网站配置:
server {
server_name website.com *.website.com;
access_log /var/log/nginx/website.com.access.log;
error_log /var/log/nginx/website.com.error.log;
root /home/website.com/public_html;
# if file doesnt exist pass to @proxy
location / {
try_files $uri $uri/ @proxy;
}
# dont log static images and set expiry
location ~* \.(jpeg|jpg|gif|png|css|js|ico)$ {
try_files $uri @proxy;
access_log off;
expires 7d;
}
# send php and other files to apache
location ~* \.(php|shtml)$ {
# proxy_pass http://127.0.0.1:8080;
fastcgi_param PATH_INFO $fastcgi_script_name;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
}
# proxy to Apache
location @proxy {
proxy_pass http://127.0.0.1:8080;
}
}
当我尝试访问测试 php 页面时,我收到 404 响应.....如果有人知道,请帮忙:)
答案1
问题是您没有定义 SCRIPT_FILENAME。您应该包含 fastcgi.conf 而不是 fastcgi_params。如果您没有 fastcgi.conf,那么您的 nginx 版本已过时,您确实应该升级。