我们需要修改nginx的配置文件,路径为/usr/local/nginx/conf/nginx.conf
,记得将指令fastcgi_intercept_errors
设置为开启状态,使得4xx和5xx错误信息被返回到客户端,并允许nginx使用error_page
指令响应错误信息。
user www www;
worker_processes auto;
error_log /home/wwwlogs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;
events {
use epoll;
worker_connections 51200;
multi_accept on;
}
http {
include mime.types;
default_type application/octet-stream;
...
#这个指令一定要设置为开启状态
fastcgi_intercept_errors on;
...
server {
listen 80 default;
server_name www.example.com;
index index.html index.htm index.php;
root /home/wwwroot/default;
#全局404页面,默认会到配置的root路径下查找,示例
error_page 404 = /404.html;
#模块404页面,配置的是全路径,示例
#location /mycms {
# error_page 404 = http://192.168.100.168/mycms/404.html;
# }
location ~ [^/]\.php(/|$)
{
#comment try_files $uri =404; to enable pathinfo
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
#include pathinfo.conf;
}
location /nginx_status {
stub_status on;
access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
access_log /home/wwwlogs/access.log access;
}
include vhost/*.conf;
}
注意:修改完配置过后记得重启Nginx
[root@server1 ~]# /usr/local/nginx/sbin/nginx -t //检查配置是否正确
[root@server1 ~]# /usr/local/nginx/sbin/nginx -s reload //重启Nginx
因为是lnmp环境,我们也可以使用lnmp命令重启所有服务:
[root@server1 ~]# lnmp restart