nginx别名配置,状态配置,include优化

一、nginx帮助参数

下面是关于/application/nginx/sbin/nginx 的参数帮助
[[email protected] 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的配置文件

 1 2.1、由于nginx主配置文件工作的时候会有很多虚拟主机维护不方便,因此会做出下面的
 2 先创建一个目录  mkdir  /application/nginx/conf//extra
 3     之后备份 cp nginx.conf nginx.conf.basename1
 4 删除server标签,添加include
 5  # Vim nginx.conf
 6 worker_processes  1;
 7 events {
 8     worker_connections  1024;
 9 }
10 http {
11     include       mime.types;
12     default_type  application/octet-stream;
13     sendfile        on;
14     keepalive_timeout  65;
15     include extra/www.conf;  --》这里添加include
16     include extra/bbs.conf
17 }
18
19 复制nginx配置文件到extra下面
20 [[email protected] conf]# cp nginx.conf.pyrene.20170320V1 extra/a
21 2.2、查找出虚拟主机的代码,然后添加到上面include创建extra/www,conf 等等文件中
22 [[email protected] extra]# sed -n "10,17p" a
23     server {
24         listen       80;
25         server_name  www.cnblogs.co;
26         location / {
27             root   html/www;
28             index  index.html index.htm;
29         }
30     }
31 [[email protected] extra]# sed -n "18,25p" a
32     server {
33         listen       80;
34         server_name  bbs.cnblogs.co;
35         location / {
36             root   html/bbs;
37             index  index.html index.htm;
38         }
39 }
40 [[email protected] extra]# sed -n "10,17p" a >www.conf
41 [[email protected] extra]# sed -n "18,25p" a >bbs.conf
42 这样就生成了两个虚拟主机
43 2.3、由于/etc/hosts里面有域名,就不用解析
44
45
46 [[email protected] conf]# /application/nginx/sbin/nginx -t    →检查语法
47 nginx: the configuration file /application/nginx-1.6.3/conf/nginx.conf syntax is ok
48 nginx: configuration file /application/nginx-1.6.3/conf/nginx.conf test is successful
49
50 [[email protected] conf]# /application/nginx/sbin/nginx -s reload   →重启
51
52 [[email protected] conf]# curl www.cnblogs.co    →查看是否成功
53 www.cnblogs.com/pyrene/

三、nginx细腻主机别名配置

 1 1、    虚拟主机别名介绍及配置
 2     所谓虚拟主机别名,就是为虚拟主机设置出了主域名意外的一个域名
 3 方法:直接在配置文件中域名哪里直接添加一个新的域名,然后域名和域名之间要用空格隔开
 4 如:
 5 1、[[email protected] extra]# vim www.conf
 6
 7     server {
 8         listen       80;
 9         server_name  www.cnblogs.co pyrene;   --》添加别名   别名之间空格就可以
10         location / {
11             root   html/www;
12             index  index.html index.htm;
13         }
14 }
15 2、[[email protected] extra]# vim bbs.conf
16
17     server {
18         listen       80;
19         server_name  bbs.cnblogs.co cnblog.co;  --》添加别名
20         location / {
21             root   html/bbs;
22             index  index.html index.htm;
23         }
24     }
25
26
27
28 2、把域名写道/etc/hosts解析
29
30 [[email protected] conf]# vim /etc/hosts
31
32 [[email protected] extra]# cat /etc/hosts
33 127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
34 ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
35 10.0.0.8 www.cnblogs.co bbs.cnblogs.co cnblog.co pyrene
36
37 3、然后检查语法,重启关闭防火墙,curl 查看就可以
38 [[email protected] extra]# curl -I pyrene
39 HTTP/1.1 200 OK
40 Server: nginx/1.8.1
41 Date: Sat, 04 Mar 2017 07:06:57 GMT
42 Content-Type: text/html
43 Content-Length: 24
44 Last-Modified: Fri, 03 Mar 2017 18:52:40 GMT
45 Connection: keep-alive
46 ETag: "58b9bb78-18"
47 Accept-Ranges: bytes
48 别名除了可以方便搜索之外,监控服务器里面监控别名,可以很好的判断每一台机器是否正常

四、Nginx状态信息配置

 1 编译的时候制定了一个状态模块  —with-http_stub_status_module 显示nginx当先的状态
 2 配置如下:
 3
 4 1、选择虚拟主机的方式增加了一个server标签到/application/nginx/conf/extra/status.conf里面,起名status.etiantian.org
 5 cat >>/application/nginx/conf/extra/status.conf<<EOF
 6 ##status
 7 server{
 8 listen 80;
 9 server_name status.cnblogs.co;
10 location / {
11   stub_status on;
12   access_log  off;
13 }
14 }
15 EOF
16
17 server_name status. status.cnblog.co;    →这里添加的域名  标签
18
19 2、需要包含,include
20 [[email protected] conf]# vim nginx.conf
21
22 worker_processes  1;
23 events {
24     worker_connections  1024;
25 }
26 http {
27     include       mime.types;
28     default_type  application/octet-stream;
29     sendfile        on;
30     keepalive_timeout  65;
31     #nginx vhosts config
32     include extra/www.conf;
33     include extra/bbs.conf;
34     include extra/blog.conf;
35     include extra/status.conf;   →这里的包含
36 }
37 3、在/etc/hosts里面解析
38 [[email protected] conf]# vim /etc/hosts
39 127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
40 ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
41 10.0.0.8 www.cnblogs.co bbs.cnblogs.co cnblog.co pyrene. status.cnblog.co  →这里就是解析
42 4、在window中解析配置 并且重启nginx

5、查看

浏览器中出现

[[email protected] conf]# curl status.cnblog.co

Active connections: 1                         →查看连接数

server accepts handled requests

16 16 16

Reading: 0 Writing: 1 Waiting: 0

上面的详细讲解

Active connections:2872

#<==表示Nginx 正处理的活动连接数 2872个

时间: 2024-08-04 14:40:13

nginx别名配置,状态配置,include优化的相关文章

Nginx、Tomcat线上环境优化配置

 Nginx.Tomcat线上环境优化配置 Nginx优化: Nginx安全方面的优化: 1. nginx安全优化,在nginx配置文件http标签段内添加"server_tokens  off"即可隐藏访问或者报错时提示web版本号信息. 2. server_tokens参数可以在http,server,location的位置添加 3. 还可以修改nginx的3个源码文件 4. 如还需要安全优化更改端口.用户. nginx 性能优化: 对于nginx配置文件中对优化比较有作用的一般为

通过浏览器查看nginx服务器状态配置方法

通过浏览器查看nginx服务器状态配置方法 投稿:junjie 字体:[增加 减小] 类型:转载 这篇文章主要介绍了通过浏览器查看nginx服务器状态配置方法,本文讲解开启nginx-status的配置方法,并对服务器的参数做了详细讲解,需要的朋友可以参考下 复制代码 代码如下: location /nginx-status { stub_status on; #access_log /var/log/nginx/mmt_nginx_status.log; access_log off; all

Web应用优化之nginx+tomcat集群配置+redis管理session

1.nginx的安装 从官网下载一个nginx事务tar.gz版本,centos系统,安装好jdk 第一步解压 第二步:解压完成进入解压目录,执行./configure命令 需要安装gcc编译和pcre库,zlib库 yum -y install gcc yum install pcre-devel yum install zlib-devel ./configure完成后执行make install即可安装成功 2.集群配置流程 一.克隆2台CentOS虚拟机,并安装jdk+tomcat 二.

nginx生产环境常用功能include 、虚拟主机别名、rewrite、nginx status详细解析

一.配置文件优化之include参数 如果我们用nginx搭建虚拟主机,虚拟主机太多,我们不能把所有配置放置在nginx.conf中吧?那样这个配置文件就太大了,看起来很乱,所有这时就产生了 include参数: 大家如果了解apache软件,就会知道apache主配置包含虚拟主机子文件的方法,其实nginx也借鉴了apache的这种包含方法 nginx的主配置文件为nginx.conf,主配置文件所包含的所有虚拟主机的子配置文件会统一放入extra(这个名字随便起的)目录中,虚拟主机的配置文件

nginx基础及其相关配置

nginx基础 Nginx的基本架构 一个master主进程,生成一个或多个worker子进程 事件驱动 epoll(边缘触发),用于Linux kqueue:用于BSD /dev/poll: IO复用器:select.poll.rt signal 支持sendfile及sendfile64 支持AIO 支持mmap 名词解释: sendfile机制:正常响应报文路径"内核空间-->用户空间-->内核空间-->客户端",如果报文在用户空间不做任何改变时,路径不再经由用

Nginx介绍及安装配置

Nginx介绍 如果听说过Apache软件那么对于Nginx也会很快就熟悉的和Apache一样nginx是开源的支持高性能高并发的WWW服务.代理服务软件以及电子邮件代理服务器并在一个BSD-like协议下发行由俄罗斯Igor Sysoev所开发开始供俄国大型的入口网址及搜索引擎Rambler使用. nginx占有内存小并发能力强特别是静态资源且功能丰富而流行起来. 从软件的功能应用方面Nginx不但是一个优秀的Web服务软件还可以具有反向代理负载均衡能和缓存服务功能.代理方面类似专业的LVS负

最全面 Nginx 入门教程 + 常用配置解析

转自 http://blog.csdn.net/shootyou/article/details/6093562 Nginx介绍和安装 一个简单的配置文件 模块介绍 常用场景配置 进阶内容 参考资料 == Nginx介绍和安装 == Nginx是一个自由.开源.高性能及轻量级的HTTP服务器及反转代理服务器, 其性能与IMAP/POP3代理服务器相当.Nginx以其高性能.稳定.功能丰富.配置简单及占用系统资源少而著称. Nginx 超越 Apache 的高性能和稳定性,使得国内使用 Nginx

Nginx简介与基础配置

何为Nginx? Nginx ("engine x") 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器.最初是为了解决C10k的问题,由Igor Sysoev为俄罗斯访问量第二的Rambler.ru站点开发的,第一个公开版本0.1.0发布于2004年10月4日. 其特性有: √模块化设计,较好的扩展性 Nginx代码完全用C语言从头写成,已经移植到许多体系结构和操作系统,包括:Linux.FreeBSD.Solaris.Mac OS X.AIX以及M

Nginx中虚拟主机配置

一.Nginx中虚拟主机配置 1.基于域名的虚拟主机配置 1.修改宿主机的hosts文件(系统盘/windows/system32/driver/etc/HOSTS) linux : vim /etc/hosts 格式: ip地址 域名 eg: 192.168.3.172 www.gerry.com 2.在nginx.conf文件中配置server段 server {   listen 80;   server_name www.gerry.com; # 域名区分       location