VPS侦探论坛

 找回密码
 注册
查看: 87011|回复: 29

lnmp之nginx如何设置404错误页面

[复制链接]
发表于 2011-1-15 10:09:25 | 显示全部楼层 |阅读模式

1.创建自己的404.html页面
2.更改nginx.conf在http定义区域加入:
fastcgi_intercept_errors on;

3.更改nginx.conf或虚拟主机的域名.conf在server 区域加入:
error_page 404 /404.html;
4.测试nginx.conf正确性:
/usr/local/nginx/sbin/nginx -t

如果正确应该显示如下信息:
the configuration file /opt/nginx/conf/nginx.conf syntax is ok
configuration file /opt/nginx/conf/nginx.conf test is successful
5.重启nginx
/usr/local/nginx/sbin/nginx -s reload
注意事项:
1.必须要添加:fastcgi_intercept_errors on; 如果这个选项没有设置,即使创建了404.html和配置了error_page也没有效果。
2.不要出于省事或者提高首页权重的目的将首页指定为404错误页面,也不要用其它方法跳转到首页。
3.自定义的404页面必须大于512字节,否则可能会出现IE默认的404页面。例如,假设自定义了404.html,大小只有11个字节(内容为:404错误)。


美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
 楼主| 发表于 2011-1-17 19:59:36 | 显示全部楼层

回复 2# 的帖子



按提示应该是error_page那一行少了一个;
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2011-1-16 22:34:57 | 显示全部楼层

回复 1# 的帖子


[emerg]: directive "error_page" is not terminated by ";" in /usr/local/nginx/conf/nginx.conf:64
configuration file /usr/local/nginx/conf/nginx.conf test failed


老大我按你的设置就出现上面那个错误。怎么解决啊
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2011-1-16 22:45:14 | 显示全部楼层



我的VPS支持伪静态,怎么弄都是不行哦。大大帮忙看看啊

[ 本帖最后由 clzz 于 2011-1-17 12:45 编辑 ]
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2011-1-17 17:03:54 | 显示全部楼层

回复 1# 的帖子


大大,帮帮忙呀。

军哥运维代购:http://shop63846532.taobao.com/

 楼主| 发表于 2011-1-17 20:00:26 | 显示全部楼层

回复 3# 的帖子


伪静态按/root/vhost.sh添加的时候的提示写上就行了
发表于 2011-1-26 06:12:19 | 显示全部楼层

为什么原本
http://我的域名.com/404test → wordpress错误页面
加入
  1. fastcgi_intercept_errors on;
  2. error_page 404 = /404.html;
复制代码
后,变成
http://我的域名.com/404test → 自定义404错误页面

要怎么像vps侦探
https://www.vpser.net/404test → wordpress错误页面
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
 楼主| 发表于 2011-1-26 10:03:04 | 显示全部楼层

回复 7# 的帖子


没加404就是显示wp的404页面,加了就显示自定义的404页面。

如果还想显示wp的404,就把自定义404去掉就行了。
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2011-2-19 09:45:27 | 显示全部楼层

配置好了
nginx.conf正确
自定义的404页面大于512字节
显示这样了,没显示自定义的那个
==================================
       404 Not Found

---------------------------------

           nginx/0.7.67

===========================

军哥运维代购:http://shop63846532.taobao.com/

发表于 2011-2-24 16:03:12 | 显示全部楼层



fastcgi_intercept_errors on;
这句不增加貌似也没问题也
好像php的404页面无法实现哦?  结果显示403

[ 本帖最后由 monface 于 2011-2-24 16:19 编辑 ]
发表于 2011-7-28 20:49:48 | 显示全部楼层

请问自己创建的404文件要放到什么位置?
 楼主| 发表于 2011-7-28 22:20:57 | 显示全部楼层

当前虚拟主机的web根目录
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2011-7-28 22:28:58 | 显示全部楼层
执行最后一步重启后,提示:

-bash: kill: cat: arguments must be process or job IDs
-bash: kill: /opt/nginx/nginx/pid: arguments must be process or job IDs

而且404既然没有生效
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2011-7-28 22:35:25 | 显示全部楼层
执行以下指令:

#/usr/local/nginx/sbin/nginx -s reload

nginx已经成功重启,同时404也已经生效

军哥运维代购:http://shop63846532.taobao.com/

发表于 2011-8-18 16:45:50 | 显示全部楼层
请教个问题安装了lnmp-0.7并安装了lnmpa  现在想知道如何设置404
感觉不起作用!!
user  www www;
worker_processes 8;
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;
        }
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 50m;
                sendfile on;
                tcp_nopush     on;
                keepalive_timeout 60;
                tcp_nodelay on;
                fastcgi_intercept_errors 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 256k;
                gzip on;
                gzip_min_length  1k;
                gzip_buffers     4 16k;
                gzip_http_version 1.0;
                gzip_comp_level 2;
                gzip_types       text/plain application/x-javascript text/css application/xml;
                gzip_vary on;
                server_tokens off;
                #limit_zone  crawler  $binary_remote_addr  10m;
server
        {
                listen       80;
                server_name 192.168.1.114;
                index index.php;
                error_page  404 /404.html;
                root  /home/wwwroot;

                location / {
                        try_files $uri @apache;
                        error_page  404 /404.html;
                        }

                location @apache {
                        internal;
                        proxy_pass http://127.0.0.1:88;
                        include proxy.conf;
                        }

                location ~ .*\.(php|php5)?$
                        {
                                proxy_pass http://127.0.0.1:88;
                                include proxy.conf;
                        }

                location /status {
                        stub_status on;
                        access_log   on;
                }

                location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
                        {
                                expires      30d;
                        }

                location ~ .*\.(js|css)?$
                        {
                                expires      12h;
                        }

                log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
             '$status $body_bytes_sent "$http_referer" '
             '"$http_user_agent" $http_x_forwarded_for';
                access_log  /home/wwwlogs/access.log  access;
        }
include vhost/*.conf;
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|VPS侦探 ( 鲁ICP备16040043号-1 )

GMT+8, 2024-4-26 23:05 , Processed in 0.031524 second(s), 18 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表