nginx别名配置,状态配置,include优化
得益于Nginx的模块化 使用Nginx 配置灵活Nginx有一个include这个 可以为nginx导入外部编写的配置 这样子很灵活下面来看看 具体使用
一、nginx帮助参数
下面是关于/application/nginx/sbin/nginx 的参数帮助
[root@A conf]# /application/nginx/sbin/nginx -h
nginx version: nginx/1.6.3
Usage: nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]
Options:
-?,-h : this help
-v : show version and exit
-V : show version and configure options then exit
-t : test configuration and exit
-q : suppress non-error messages during configuration testing
-s signal : send signal to a master process: stop, quit, reopen, reload
-p prefix : set prefix path (default: /application/nginx-1.6.3/)
-c filename : set configuration file (default: conf/nginx.conf)
-g directives : set global directives out of configuration file
重启要学脚本,检查api端口,如果没问题就重启,如果有问题恢复到原来的模式
利用include功能优化nginx的配置文件
由于nginx主配置文件工作的时候会有很多虚拟主机维护不方便,因此会做出下面的
1、先创建一个目录 mkdir /application/nginx/conf//extra
2、之后备份 cp nginx.conf nginx.conf.pyrene
3、增加include
[root@oldboy conf]# cat 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;
}
4、配置server标签
[root@oldboy conf]# cp nginx.conf.pyrene extra/a
[root@oldboy conf]# cd extra/
[root@oldboy extra]# ls
a
[root@oldboy extra]# sed -n "10,17p" a>www.conf
[root@oldboy extra]# sed -n "18,25p" a>bbs.conf
5、重启
nginx细腻主机别名配置
1、 虚拟主机别名介绍及配置
所谓虚拟主机别名,就是为虚拟主机设置出了主域名意外的一个域名
方法:直接在配置文件中域名哪里直接添加一个新的域名,然后域名和域名之间要用空格隔开
如:
1、[root@oldboy extra]# vim www.conf
server {
listen 80;
server_name www.cnblogs.co pyrene; --》添加别名 别名之间空格就可以
location / {
root html/www;
index index.html index.htm;
}
}
2、[root@oldboy extra]# vim bbs.conf
server {
listen 80;
server_name bbs.cnblogs.co cnblog.co; --》添加别名
location / {
root html/bbs;
index index.html index.htm;
}
}
2、把域名写道/etc/hosts解析
[root@A conf]# vim /etc/hosts
[root@oldboy extra]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.0.0.8 www.cnblogs.co bbs.cnblogs.co cnblog.co pyrene
3、然后检查语法,重启关闭防火墙,curl 查看就可以
[root@oldboy extra]# curl -I pyrene
HTTP/1.1 200 OK
Server: nginx/1.8.1
Date: Sat, 04 Mar 2017 07:06:57 GMT
Content-Type: text/html
Content-Length: 24
Last-Modified: Fri, 03 Mar 2017 18:52:40 GMT
Connection: keep-alive
ETag: "58b9bb78-18"
Accept-Ranges: bytes
别名除了可以方便搜索之外,监控服务器里面监控别名,可以很好的判断每一台机器是否正常
Nginx状态信息配置
编译的时候制定了一个状态模块 —with-http_stub_status_module 显示nginx当先的状态
配置如下:
1、选择虚拟主机的方式增加了一个server标签到/application/nginx/conf/extra/status.conf里面,起名status.etiantian.org
cat >>/application/nginx/conf/extra/status.conf<<EOF
##status
server{
listen 80;
server_name status.cnblogs.co;
location / {
stub_status on;
access_log off;
}
}
EOF
server_name status. status.cnblog.co; →这里添加的域名 标签
2、需要包含,include
[root@A conf]# vim nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
#nginx vhosts config
include extra/www.conf;
include extra/bbs.conf;
include extra/blog.conf;
include extra/status.conf; →这里的包含
}
3、在/etc/hosts里面解析
[root@A conf]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.0.0.8 www.cnblogs.co bbs.cnblogs.co cnblog.co pyrene. status.cnblog.co →这里就是解析
4、在window中解析配置 并且重启
Comments | NOTHING