知識點021-Nginx 的配置文件

1.剛剛安裝時的主配置文件html

[root@web01 conf]# egrep -v "^$|#" nginx.conf
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;
        }
    }
}

2. 虛擬主機nginx

在web服務裏面就是獨立的站點web

在/application/nginx/conf建立extra
[root@web01 conf]# pwd
/application/nginx/conf
[root@web01 conf]# mkdir extra
[root@web01 conf]#
 將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;
    include extra/blog.conf;
}

3. 給上列的/extra/*.conf 進行配置bash

進入extra目錄下
[root@web01 conf]# cd extra/
[root@web01 extra]# pwd
/application/nginx/conf/extra
[root@web01 extra]#   
 分別建立以下三個配置文件,而且寫入配置信息
[root@web01 extra]# touch www.conf
[root@web01 extra]# touch bbs.conf
[root@web01 extra]# touch blog.conf
[root@web01 extra]#
[root@web01 extra]# cat www.conf 
    server {
        listen       80;
        server_name  www.123456.com;
        location / {
            root   html/www;
            index  index.html index.htm;
        }
}
[root@web01 extra]# cat bbs.conf 
    server {
        listen       80;
        server_name  bbs.123456.com;
        location / {
            root   html/bbs;
            index  index.html index.htm;
        }
}
[root@web01 extra]#
[root@web01 extra]# cat blog.conf 
    server {
        listen       80;
        server_name  blog.123456.com;
        location / {
            root   html/blog;
            index  index.html index.htm;
        }
}

4. status.conf的創建app

在/application/nginx/conf/extra建立編寫status.conf,內容以下
##status
server{
    listen  80;
    server_name  status.123456.com;
    location / {
        stub_status on;
        access_log  off;
   }
 }

5.在計算機本地輸入drivers 下的/etc/hosts  中添加以上的解析.net

10.0.110.11   www.123456.com
10.0.110.11   bbs.123456.com
10.0.110.11   blog.123456.com
10.0.110.11   status.123456.com

6.定義訪問日誌並放入定時腳本中,通常企業不會這麼用, 由於企業不會天天平滑重啓nginx 日誌

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    include extra/www.conf;
    include extra/bbs.conf;
    include extra/blog.conf;
    include extra/status.conf;
}

而後配置www.conf code

server {
        listen       80;
        server_name  www.jimmy.com;
        location / {
            root   html/www;
            index  index.html index.htm;
        }
      access_log   logs/www_access.log   main;
}

編寫腳本orm

#!/bin/bash
cd /application/nginx/logs
/bin/mv www_access.log www_access_$(date +%F)
/application/nginx/sbin/nginx -s reload

7. 以上是熟悉nginx的幾項配置文件, 具體信息能夠百度server

其它nginx的博文:

http://blog.csdn.net/wangpengqi/article/details/17224531

https://www.cnblogs.com/hanyinglong/p/5141504.html

相關文章
相關標籤/搜索