Nginx设置404跳转


Nginx 设置 404 页面跳转

1.打开你的Nginx.conf文件

vim /etc/nginx/nginx.con

2.在http里面添加启用error_page

proxy_intercept_errors on;

3.在server 里设置你要跳转的链接

error_page 404 http://fuchenchenle.cn/404/;    #一定要写http
我的配置文件

第32行和第50行 就是我们添加的配置

# For more information on configuration, see:
  2 #   * Official English Documentation: http://nginx.org/en/docs/
  3 #   * Official Russian Documentation: http://nginx.org/ru/docs/
  4 
  5 user nginx;
  6 worker_processes auto;
  7 error_log /var/log/nginx/error.log;
  8 pid /run/nginx.pid;
  9 
 10 # Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
 11 include /usr/share/nginx/modules/*.conf;
 12 
 13 events {
 14     worker_connections 1024;
 15 }
 16 
 17 http {
 18     log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
 19                       '$status $body_bytes_sent "$http_referer" '
 20                       '"$http_user_agent" "$http_x_forwarded_for"';
 21 
 22     access_log  /var/log/nginx/access.log  main;
 23 
 24     sendfile            on;
 25     tcp_nopush          on;
 26     tcp_nodelay         on;
 27     keepalive_timeout   65;
 28     types_hash_max_size 2048;
 29 
 30     include             /etc/nginx/mime.types;
 31     default_type        application/octet-stream;
 32     proxy_intercept_errors on;
 33     # Load modular configuration files from the /etc/nginx/conf.d directory.
 34     # See http://nginx.org/en/docs/ngx_core_module.html#include
 35     # for more information.
 36     include /etc/nginx/conf.d/*.conf;
 37 
 38     server {
 39         listen       80 default_server;
 40         listen       [::]:80 default_server;
 41         server_name  49.232.59.235;
 42         root         /home/hexo;
 43 
 44         # Load configuration files for the default server block.
 45         include /etc/nginx/default.d/*.conf;
 46 
 47         location / {
 48         }
 49 
 50         error_page 404 http://fuchenchenle.cn/404/;
 51     }

文章作者: Fuchenchenle
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 Fuchenchenle !
 上一篇
20年东营市网络搭建赛题解法 20年东营市网络搭建赛题解法
20年东营市网络搭建赛题解法这种年年都是主办方拿奖的比赛,什么成分懂得都懂 准备工作1.所有云主机都要设置ip2.关闭防火墙和selinux setenforce 0 systemctl stop firewall 3.所有主机配置yum源
2020-09-10 Fuchenchenle
下一篇 
hexo+nginx配置ssl证书 hexo+nginx配置ssl证书
Hexo+Nginx 部署SSL证书一、部署准备1.环境本地windows10操作系统 腾讯云服务器(Centos7.6) 2.准备SSL证书 Filezilla 软件来上传ssl证书 二.安装FTP服务 1.安装vsftpd yum in
2020-08-19
  目录