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

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

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

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

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

yum install -y nginx

2、啟動(dòng) nginx

systemctl start nginx
systemctl enable nginx

3、配置 nginx 反向代理 http://10.2.1.16。
開通 nginx 服務(wù)器訪問 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、測試

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

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

相關(guān)文章

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

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

    本文介紹了Nginx的安裝、配置和啟動(dòng)等步驟,詳細(xì)介紹了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àng)目的實(shí)現(xiàn)

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

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

    Nginx的rewrite模塊詳解

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

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

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

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

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

    win10上安裝nginx的方法步驟

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

    Nginx報(bào)錯(cuò)“Too many open files”的問題解決

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

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

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

最新評論

通城县| 安泽县| 铅山县| 北辰区| 大宁县| 武陟县| 阜康市| 邢台市| 义马市| 珠海市| 墨竹工卡县| 淳安县| 永安市| 枣庄市| 抚松县| 宣威市| 会昌县| 临西县| 灵山县| 桂林市| 中方县| 梅州市| 山东省| 平昌县| 长宁区| 琼海市| 克拉玛依市| 乌鲁木齐市| 石林| 灵寿县| 茂名市| 塔城市| 三门峡市| 浦东新区| 青铜峡市| 县级市| 肇州县| 光山县| 洛扎县| 乌鲁木齐县| 松阳县|