@yanglt7
2018-10-21T15:53:53.000000Z
字数 3847
阅读 718
Web集群实战
Nginx 的主配置文件为 nginx.conf ,主配置文件包含的所有虚拟主机的子配置文件会统一放入 extra 目录中,虚拟主机的配置文件按照网站的域名或功能取名。
使用的参数是 include,语法:
include file | mask;
include mime.type;include www.conf; // 包含单个文件include vhosts/*.conf // 包含 vhosts 下所有以 conf 结尾的文件
[root@ylt001 conf]# mkdir extra[root@ylt001 conf]# /bin/cp nginx.conf_BaseName nginx.conf[root@ylt001 conf]# sed -n '10,17p' nginx.confServer {listen 80;server_name www.yangyangyang.org;location / {root html/www;index.html index.htm;}}[root@ylt001 conf]# sed -n '10,17p' nginx.conf >extra/www.conf[root@ylt001 conf]# sed -n '18,25p' nginx.confServer {listen 80;server_name bbs.yangyangyang.org;location / {root html/bbs;index.html index.htm;}}[root@ylt001 conf]# sed -n '18,25p' nginx.conf >extra/bbs.conf[root@ylt001 conf]# sed -n '26,33p' nginx.confServer {listen 80;server_name blog.yangyangyang.org;location / {root html/blog;index.html index.htm;}}[root@ylt001 conf]# sed -n '26,33p' nginx.conf >extra/blog.conf
worker_processes 1;events {worker_connections 1024;}http {include mime.types;default_type application/octet-stream;sendfile on;keepalived_timeout 65;}
[root@ylt001 conf]# sed -i '10 include extra/www.conf; \ninclude extra/bbs.conf; \ninclude extra/blog.conf;' nginx.conf
worker_processes 1;events {worker_connections 1024;}http {include mime.types;default_type application/octet-stream;sendfile on;keepalived_timeout 65;include extra/www.conf;include extra/bbs.conf;include extra/blog.conf;}
[root@ylt001 conf]# ../sbin/nginx -t[root@ylt001 conf]# ../sbin/nginx -s reload[root@ylt001 conf]# tail -1 /etc/hosts[root@ylt001 conf]# curl www.yangyangyang.org[root@ylt001 conf]# curl blog.yangyangyang.org[root@ylt001 conf]# curl bbs.yangyangyang.org
Server {listen 80;server_name www.yangyangyang.org yangyangyang.org;location / {root html/www;index.html index.htm;}}
[root@ylt001 conf]# ../sbin/nginx -t[root@ylt001 conf]# ../sbin/nginx -s reload
[root@ylt001 conf]# vi /etc/hosts[root@ylt001 conf]# tail -1 /etc/hosts[root@ylt001 conf]# curl www.yangyangyang.org[root@ylt001 conf]# curl yangyangyang.org
记录 Nginx 的基本访问信息
检查编译安装 Nginx 时是否设定了 http_stub_status_module 模块
[root@ylt001 conf]# ../sbin/nginx -V
[root@ylt001 conf]# cat >>/application/nginx/conf/extra/status.conf<<EOF>##status>server{> listen 80;> server_name status.yangyangyang.org;> location / {> stub_status on;> access_log off;> }>}>EOF[root@ylt001 conf]# cat extra/status.conf[root@ylt001 conf]# sed -i '13 i include extra/status.conf;' nginx.conf[root@ylt001 conf]# cat -n nginx.confworker_processes 1;events {worker_connections 1024;}http {include mime.types;default_type application/octet-stream;sendfile on;keepalived_timeout 65;include extra/www.conf;include extra/bbs.conf;include extra/blog.conf;include extra/status.conf}
[root@ylt001 conf]# ../sbin/nginx -t[root@ylt001 conf]# ../sbin/nginx -s reload
error_log file level关键字 日志文件 错误日志级别
#default: error_log logs/error.log error;
#context: main, http, server, location
参考资料:http://nginx.org/en/docs/ngx_core_module.html#error_log
worker_processes 1;error_log logs/error.log;events {worker_connections 1024;}http {include mime.types;default_type application/octet-stream;sendfile on;keepalived_timeout 65;include extra/www.conf;include extra/bbs.conf;include extra/blog.conf;include extra/status.conf;}