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

Nginx安裝后常用功能配置基礎(chǔ)篇

 更新時間:2022年03月19日 11:36:13   作者:、重明  
這篇文章主要介紹了Nginx安裝后常用的功能配置,為了在使用中更高效簡潔,Nginx安裝后通常會進行一些常用的配置,有需要的朋友可以借鑒參考下,希望能夠有所幫助

1.主配置文件與虛擬主機分離

如果虛擬主機很多的話,進行分離看起來會更方便,還可以按功能、業(yè)務(wù)進行劃分,下面以兩個虛擬主機為例。

完整的除去空行和注釋后的配置文件:

[root@nginx-01 conf]# egrep -v "#|^$" nginx.conf.bak 
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

創(chuàng)建/app/nginx/conf目錄下虛擬主機配置目錄

mkdir extra

利用server模塊創(chuàng)建www和bbs兩個虛擬站點

[root@nginx-01 conf]# cat -n nginx.conf
[root@nginx-01 conf]# sed -n '10,20p' nginx.conf
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

www站點

[root@nginx-01 conf]# cat extra/www.conf 
    server {
        listen       80;
        server_name  www.yygg.com;
        location / {
            root   html/www;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

bbs站點

[root@nginx-01 conf]# cat extra/bbs.conf 
    server {
        listen       80;
        server_name  bbs.yygg.com;
        location / {
            root   html/bbs;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html/bbs;
        }
    }

主配置文件配置(nginx.conf)

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
include extra/www.conf;
include extra/bbs.conf;
}

檢查配置

[root@nginx-01 conf]# /app/nginx/sbin/nginx -t
nginx: the configuration file /app/nginx-1.18.0//conf/nginx.conf syntax is ok
nginx: configuration file /app/nginx-1.18.0//conf/nginx.conf test is successful

創(chuàng)建站點目錄

[root@nginx-01 conf]# mkdir /app/nginx/html/{www,bbs}
[root@nginx-01 conf]# echo "http://www.yygg.com" >>/app/nginx/html/www/index.html
[root@nginx-01 conf]# echo "http://bbs.yygg.com" >>/app/nginx/html/bbs/index.html
[root@nginx-01 conf]# echo "192.168.1.5 www.yygg.com bbs.yygg.com" >>/etc/hosts

啟動服務(wù)并測試

[root@nginx-01 conf]# /app/nginx/sbin/nginx
[root@nginx-01 conf]# curl www.yygg.com
http://www.yygg.com
[root@nginx-01 conf]# curl bbs.yygg.com
http://bbs.yygg.com

2.虛擬主機別名設(shè)置

以www站點為例,設(shè)置別名
所謂別名就是除了主域名外額外設(shè)置一個或多個域名

www.yygg.com設(shè)置別名yygg.com。

[root@nginx-01 conf]# cat extra/www.conf 
    server {
        listen       80;
        server_name  www.yygg.com yygg.com;
        location / {
            root   html/www;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html/www;
        }
    }

重啟nginx測試

[root@nginx-01 conf]# /app/nginx/sbin/nginx -s reload
[root@nginx-01 conf]# cat /etc/hosts
192.168.1.5 www.yygg.com bbs.yygg.com yygg.com
[root@nginx-01 conf]# curl yygg.com
http://www.yygg.com

3.Nginx status狀態(tài)信息配置

狀態(tài)信息記錄使用的是`ngx_http_stub_status_module`模塊實現(xiàn)

輸入/app/nginx/sbin/nginx -V檢查編譯是否有上述模塊:

nginx version: nginx/1.18.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --user=nginx --group=nginx --prefix=/app/nginx-1.18.0/ --with-http_stub_status_module --with-http_ssl_module

創(chuàng)建一個status的虛擬主機,方式參考標題1,status.conf配置文件如下:

    server {
        listen       80;
        server_name  status.yygg.com;
        location / {
            stub_status on;
            access_log off;
        }
    }

主配置文件nginx.conf追加status虛擬主機配置

sed -i '11 i include extra/status.conf;' nginx.conf

檢查語法并重啟nginx

/app/nginx/sbin/nginx -t
/app/nginx/sbin/nginx -s reload

配置hosts解析

192.168.1.5 status.yygg.com

訪問status.yygg.com查看

[root@nginx-01 conf]# curl status.yygg.com
Active connections: 1 
server accepts handled requests
 4 4 4 
Reading: 0 Writing: 1 Waiting: 0 

顯示結(jié)果解析:

Active connections: 1  ##正處理的連接數(shù)為1
server  ##共處理了4次連接
accepts  ##共創(chuàng)建了4次握手
handled requests  ##共處理了4次請求
Reading  ##讀取到客戶端的Header信息數(shù)
Writing  ##返回給客戶端的Header信息數(shù)
Waiting  ##NGinx已經(jīng)處理完正在等候下一次請求的指令的駐留連數(shù)

4.增加錯誤日志

error_log語法:

error_log    file    level;

關(guān)鍵字不變,file是日志存放位置,level是錯誤日志級別

通常只用warn|error|crit三個級別

配置錯誤日志配置,在nging.conf文件中worker_processes 1;下添加

error_loglogs/error_log;

沒錯,就這一行!

以上就是Nginx安裝后常用功能配置的詳細內(nèi)容,更多關(guān)于Nginx功能配置的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Nginx三種不同類型的虛擬主機的配置(基于域名、IP 和端口)

    Nginx三種不同類型的虛擬主機的配置(基于域名、IP 和端口)

    本文主要介紹了Nginx多種虛擬主機配置方式,能夠根據(jù)域名、IP 或端口區(qū)分不同的站點,本文就來介紹一下,感興趣的可以了解一下
    2025-04-04
  • 騰訊云CentOS 6.6快速安裝 Nginx服務(wù)器圖文教程

    騰訊云CentOS 6.6快速安裝 Nginx服務(wù)器圖文教程

    本文通過圖文并茂的形式給大家介紹了騰訊云CentOS 6.6快速安裝 Nginx服務(wù)器的方法,介紹的非常詳細,具有參考借鑒價值,感興趣的朋友一起看看吧
    2016-09-09
  • 深入理解Nginx的proxy_cache模塊

    深入理解Nginx的proxy_cache模塊

    Nginx的proxy_cache模塊提供了強大而靈活的緩存功能,本文主要介紹了深入理解Nginx的proxy_cache模塊,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2024-08-08
  • Nginx代理接口訪問返回404的實現(xiàn)示例

    Nginx代理接口訪問返回404的實現(xiàn)示例

    因為不同業(yè)務(wù)系統(tǒng)間有接口調(diào)用,存在跨域問題,為了解決同源策略,需要將接口通過nginx去轉(zhuǎn)發(fā),本文主要介紹了Nginx代理接口訪問返回404的實現(xiàn)示例,感興趣的可以了解一下
    2024-06-06
  • nginx https 443端口配置的方法

    nginx https 443端口配置的方法

    本文主要介紹了nginx https 443端口配置的方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2023-03-03
  • CentOS 7下編譯安裝Nginx 1.11.10教程

    CentOS 7下編譯安裝Nginx 1.11.10教程

    這篇文章主要介紹了在CentOS 7下編譯安裝Nginx 1.11.10的方法,文中給出了詳細的安裝步驟,相信對大家具有一定的參考價值,需要的朋友們下面來一起看看吧。
    2017-03-03
  • nginx基于域名,端口,不同IP的虛擬主機設(shè)置的實現(xiàn)

    nginx基于域名,端口,不同IP的虛擬主機設(shè)置的實現(xiàn)

    這篇文章主要介紹了nginx基于域名,端口,不同IP的虛擬主機設(shè)置,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-11-11
  • docker部署nginx并且掛載文件夾和文件操作

    docker部署nginx并且掛載文件夾和文件操作

    這篇文章主要介紹了docker部署nginx并且掛載文件夾和文件操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-11-11
  • 前端將項目部署到服務(wù)器(Nginx)的完整步驟

    前端將項目部署到服務(wù)器(Nginx)的完整步驟

    最近寫了一個項目,需要進行手機上測試,下面就需要前端自己將項目進行部署,這篇文章主要給大家介紹了關(guān)于前端將項目部署到服務(wù)器(Nginx)的相關(guān)資料,文中通過圖文介紹的非常詳細,需要的朋友可以參考下
    2023-01-01
  • 使用Nginx搭建圖片服務(wù)器(windows環(huán)境下)

    使用Nginx搭建圖片服務(wù)器(windows環(huán)境下)

    這篇文章主要介紹了使用Nginx搭建圖片服務(wù)器(windows環(huán)境下),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-06-06

最新評論

当阳市| 曲周县| 东乡族自治县| 华亭县| 资源县| 华阴市| 太白县| 扶余县| 阜城县| 天门市| 七台河市| 邓州市| 慈利县| 新郑市| 黑龙江省| 宁国市| 中江县| 永丰县| 太湖县| 广德县| 房山区| 嘉禾县| 屯留县| 大余县| 靖西县| 英吉沙县| 贵南县| 云南省| 德化县| 临漳县| 新昌县| 五峰| 泰顺县| 沙坪坝区| 昭通市| 仁化县| 凤庆县| 历史| 峨眉山市| 包头市| 屯门区|