最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

nginx 自定義 404、50x 錯誤頁面的實現(xiàn)

 更新時間:2024年12月22日 09:23:16   作者:Man_In_The_Night  
本文主要介紹了nginx 自定義 404、50x 錯誤頁面的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

環(huán)境 centos7.6、 nginx 1.16.1

1、安裝 nginx,需要配置 epel 源(略)

yum install -y nginx

2、啟動 nginx

systemctl start nginx
systemctl enable nginx

3、配置 nginx 反向代理 http://10.2.1.16。
開通 nginx 服務器訪問 10.2.1.16 端口權(quán)限(略)
這里配置 worker_processes 4,一般根 cpu 核數(shù)一致
worker_connections 1024,跟內(nèi)存大小相關(guān)
修改 404 html 頁面到 custom_404.html
修改 50x html 頁面到 custom_50x.html

[root@ansible002 ~]# cat /etc/nginx/nginx.conf
user nginx;
worker_processes 4;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include

    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen 90;
        server_name localhost;

        include /etc/nginx/default.d/*.conf;

        location / {
        proxy_pass http://10.2.1.16;
        }
      
       #修改 404 html 頁面到 custom_404.html
        error_page 404 /custom_404.html;
        location /custom_404.html {
        root /usr/share/nginx/html;
        internal;
        }
        
       #修改 50x html 頁面到 custom_50x.html
        error_page 500 502 503 504 /custom_50x.html;
        location /custom_50x.html {
        root /usr/share/nginx/html;
        internal;
        }

    }
}

4、編輯 404、50x html 文件

[root@ansible002 ~]# cat /usr/share/nginx/html/custom_404.html 
<h1 style='color:red'>Error 404: Not found :</h1>
<p>I have no idea where that file is, sorry.  Are you sure you typed in the correct URL?</p>
[root@ansible002 ~]# cat /usr/share/nginx/html/custom_50x.html 
<h1>Oops! Something went wrong...</h1>
<p>We seem to be having some technical difficulties. Hang tight.</p>

5、更新 nginx 配置

nginx -s reload

6、測試

訪問一個不存在的頁面測試 404,比如 http://nginx_ip/xxx。
修改 proxy_pass http://10.2.1.16 為proxy_pass http://10.2.1.16:9099;,代理一個不存在的服務,nginx -s reload, 訪問 http://nginx_ip 測試 50x

到此這篇關(guān)于nginx 自定義 404、50x 錯誤頁面的實現(xiàn)的文章就介紹到這了,更多相關(guān)nginx 404、50x 錯誤頁面內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Nginx 安裝配置及常用命令詳解

    Nginx 安裝配置及常用命令詳解

    本文介紹了Nginx的安裝、配置和啟動等步驟,詳細介紹了Nginx的配置文件結(jié)構(gòu)和常用命令,感興趣的朋友跟隨小編一起看看吧
    2026-04-04
  • lnmp環(huán)境中如何為nginx開啟pathinfo

    lnmp環(huán)境中如何為nginx開啟pathinfo

    這篇文章主要介紹了lnmp環(huán)境中如何為nginx開啟pathinfo的方法,操作很簡單,需要的朋友可以參考下
    2015-01-01
  • nginx 解決首頁跳轉(zhuǎn)問題詳解

    nginx 解決首頁跳轉(zhuǎn)問題詳解

    這篇文章主要介紹了nginx 解決首頁跳轉(zhuǎn)問題詳解的相關(guān)資料,需要的朋友可以參考下
    2016-12-12
  • centos7下基于nginx+uwsgi部署Django項目的實現(xiàn)

    centos7下基于nginx+uwsgi部署Django項目的實現(xiàn)

    Django是一個開源的Web應用框架,使用Python語言編寫,主要用于搭建Web項目,本教程介紹如何在centos7下基于nginx+uwsgi部署Django項目的實現(xiàn),感興趣的可以了解一下
    2024-04-04
  • Nginx的rewrite模塊詳解

    Nginx的rewrite模塊詳解

    這篇文章主要介紹了Nginx的rewrite模塊詳解,有感興趣的同學可以研究下
    2021-02-02
  • keepalived+nginx實現(xiàn)雙服務器主備方案

    keepalived+nginx實現(xiàn)雙服務器主備方案

    本文主要介紹了使用keepalived和nginx實現(xiàn)雙服務器主備方案,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2024-12-12
  • Ubuntu+Nginx+Mysql+Php+Zend+eaccelerator安裝配置文字版

    Ubuntu+Nginx+Mysql+Php+Zend+eaccelerator安裝配置文字版

    把我架設lnmp網(wǎng)站的過程寫出來,希望對想架設網(wǎng)站的朋友有所幫助,如有更好的辦法請?zhí)岢鰜?/div> 2012-02-02
  • win10上安裝nginx的方法步驟

    win10上安裝nginx的方法步驟

    這篇文章主要介紹了win10上安裝nginx的方法步驟,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-10-10
  • Nginx報錯“Too many open files”的問題解決

    Nginx報錯“Too many open files”的問題解決

    本文主要介紹了Nginx報錯“Too many open files”的問題解決,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2025-05-05
  • Nginx IP限制與路徑訪問控制配置

    Nginx IP限制與路徑訪問控制配置

    在某些應用場景下,特定路徑需要免登錄訪問,本文主要介紹了Nginx IP限制與路徑訪問控制配置,文中通過示例代碼介紹的非常詳細,需要的朋友們下面隨著小編來一起學習學習吧
    2024-08-08

最新評論

保亭| 五原县| 华池县| 南华县| 保定市| 睢宁县| 建昌县| 扬中市| 穆棱市| 元氏县| 沧州市| 伊宁市| 砀山县| 磴口县| 荃湾区| 长岭县| 屯门区| 班戈县| 广昌县| 伊春市| 井研县| 北安市| 赫章县| 建宁县| 高雄市| 徐汇区| 镇雄县| 宁安市| 开封县| 徐水县| 永丰县| 庄浪县| 纳雍县| 平安县| 来宾市| 朝阳县| 威海市| 潼关县| 甘孜| 文成县| 丁青县|