欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

環(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 服務(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、測試

訪問一個不存在的頁面測試 404,比如 http://nginx_ip/xxx。
修改 proxy_pass http://10.2.1.16 為proxy_pass http://10.2.1.16:9099;,代理一個不存在的服務(wù),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搭建高可用集群的實現(xiàn)方法

    nginx搭建高可用集群的實現(xiàn)方法

    本文主要介紹了nginx搭建高可用集群的實現(xiàn)方法,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-01-01
  • nginx不支持apk ipa文件下載的設(shè)置方法

    nginx不支持apk ipa文件下載的設(shè)置方法

    今天在幫客戶配置nginx服務(wù)器的時候,對方需要支持apk ipa文件下載,這里簡單分享下,方便需要的朋友
    2014-03-03
  • nginx+lua(openresty)實現(xiàn)黑/白名單權(quán)限控制的示例

    nginx+lua(openresty)實現(xiàn)黑/白名單權(quán)限控制的示例

    本文介紹了如何使用Openresty進行權(quán)限控制和灰度發(fā)布,具體通過定時器定期更新黑名單數(shù)據(jù),進行用戶過濾和權(quán)限管控,具有一定的參考價值,感興趣的可以了解一下
    2024-09-09
  • nginx?rtmp模塊編譯?arm版本的問題

    nginx?rtmp模塊編譯?arm版本的問題

    這篇文章主要介紹了nginx?rtmp模塊編譯?arm版本的問題,pcre庫和libz庫都不用單獨編譯,在編譯nginx時添加模塊時一起編譯,需要的朋友可以參考下
    2021-12-12
  • Nginx開源可視化配置工具NginxConfig使用教程

    Nginx開源可視化配置工具NginxConfig使用教程

    這篇文章主要為大家介紹了Nginx開源可視化配置工具NginxConfig使用示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-06-06
  • nginx http響應(yīng)限速的具體實現(xiàn)

    nginx http響應(yīng)限速的具體實現(xiàn)

    本文主要介紹了nginx http響應(yīng)限速的具體實現(xiàn),可以使用limite_rate和limit_rate_after來限制HTTP響應(yīng)的速度,具有一定的參考價值,感興趣的可以了解一下
    2024-05-05
  • 圖文詳解Nginx版本平滑升級方案

    圖文詳解Nginx版本平滑升級方案

    Nginx平滑升級就是指在不停止業(yè)務(wù)的前提下,實現(xiàn)對Nginx軟件版本的升級,下面這篇文章主要給大家介紹了關(guān)于Nginx版本平滑升級方案的相關(guān)資料,需要的朋友可以參考下
    2021-09-09
  • Nginx反向代理springboot的jar包過程解析

    Nginx反向代理springboot的jar包過程解析

    這篇文章主要介紹了Nginx反向代理springboot的jar包過程解析,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-05-05
  • nginx設(shè)置目錄白名單、ip白名單的實現(xiàn)方法

    nginx設(shè)置目錄白名單、ip白名單的實現(xiàn)方法

    今天小編就為大家分享一篇nginx設(shè)置目錄白名單、ip白名單的實現(xiàn)方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-08-08
  • nginx負載均衡下的webshell上傳的實現(xiàn)

    nginx負載均衡下的webshell上傳的實現(xiàn)

    本文主要介紹了nginx負載均衡下的webshell上傳的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-03-03

最新評論