知识点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

相关文章
相关标签/搜索