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

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

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

1.主配置文件與虛擬主機(jī)分離

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

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

[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目錄下虛擬主機(jī)配置目錄

mkdir extra

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

[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站點(diǎn)

[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站點(diǎn)

[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)建站點(diǎn)目錄

[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

啟動(dòng)服務(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.虛擬主機(jī)別名設(shè)置

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

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`模塊實(shí)現(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)建一個(gè)status的虛擬主機(jī),方式參考標(biāo)題1,status.conf配置文件如下:

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

主配置文件nginx.conf追加status虛擬主機(jī)配置

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.增加錯(cuò)誤日志

error_log語法:

error_log    file    level;

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

通常只用warn|error|crit三個(gè)級(jí)別

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

error_loglogs/error_log;

沒錯(cuò),就這一行!

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

相關(guān)文章

  • 升級(jí)nginx以支持http2的方法

    升級(jí)nginx以支持http2的方法

    本篇文章主要介紹了升級(jí)nginx以支持http2的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-03-03
  • Nginx中IF、AND、OR語句用法實(shí)例

    Nginx中IF、AND、OR語句用法實(shí)例

    這篇文章主要介紹了Nginx中IF、AND、OR語句用法實(shí)例,本文講解的是Ningx中的邏輯判斷語句用法,需要的朋友可以參考下
    2015-02-02
  • Nginx對某個(gè)目錄設(shè)置密碼保護(hù)例子

    Nginx對某個(gè)目錄設(shè)置密碼保護(hù)例子

    這篇文章主要介紹了Nginx對某個(gè)目錄設(shè)置密碼保護(hù)例子,使用htpasswd 生成用戶名和密碼,并解決了打開PHP文件變成文件下載的問題,需要的朋友可以參考下
    2014-06-06
  • Nginx 請求壓縮的實(shí)現(xiàn)(動(dòng)態(tài)壓縮,靜態(tài)壓縮)

    Nginx 請求壓縮的實(shí)現(xiàn)(動(dòng)態(tài)壓縮,靜態(tài)壓縮)

    本文主要介紹了Nginx 請求壓縮的實(shí)現(xiàn)(動(dòng)態(tài)壓縮,靜態(tài)壓縮),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-03-03
  • Nginx圖片防盜鏈配置實(shí)例

    Nginx圖片防盜鏈配置實(shí)例

    這篇文章主要介紹了Nginx圖片防盜鏈配置實(shí)例,并對代碼做了詳細(xì)的說明,讓你充分理解配置的意圖,需要的朋友可以參考下
    2014-07-07
  • nginx之queue的具體使用

    nginx之queue的具體使用

    本文主要介紹了nginx之queue的具體使用,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-06-06
  • nginx使用rewrite報(bào)錯(cuò)的解決

    nginx使用rewrite報(bào)錯(cuò)的解決

    本文主要介紹了nginx使用rewrite報(bào)錯(cuò)的解決,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-03-03
  • nginx關(guān)閉favicon.ico、robots.txt日志記錄配置

    nginx關(guān)閉favicon.ico、robots.txt日志記錄配置

    這篇文章主要介紹了nginx關(guān)閉favicon.ico、robots.txt日志記錄配置,同時(shí)提供了不允許訪問某些隱藏文件的配置方法,需要的朋友可以參考下
    2014-05-05
  • window下使用nginx提供文件下載服務(wù)器配置

    window下使用nginx提供文件下載服務(wù)器配置

    這篇文章主要介紹了window下使用nginx提供文件下載服務(wù)器配置,需要的朋友可以參考下
    2017-06-06
  • Nginx反向代理轉(zhuǎn)發(fā)tomcat的實(shí)現(xiàn)

    Nginx反向代理轉(zhuǎn)發(fā)tomcat的實(shí)現(xiàn)

    本文主要介紹了Nginx反向代理轉(zhuǎn)發(fā)tomcat的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-07-07

最新評(píng)論