一、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、 虛擬主機別名介紹及配置 2 所謂虛擬主機別名,就是為虛擬主機設置出了主域名意外的一個域名 3 方法:直接在配置文件中域名哪里直接添加一個新的域名,然后域名和域名之間要用空格隔開 4 如: 5 1、[root@oldboy 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、[root@oldboy 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 [root@A conf]# vim /etc/hosts 31 32 [root@oldboy 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 [root@oldboy 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 [root@A 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 [root@A 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、查看
瀏覽器中出現
[root@A 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個