日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > Nginx >内容正文

Nginx

【Nginx】Nginx配置文件参数/启动参数详解;启动/停止/重新加载配置命令

發(fā)布時(shí)間:2024/2/28 Nginx 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【Nginx】Nginx配置文件参数/启动参数详解;启动/停止/重新加载配置命令 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

nginx配置文件

nginx及其模塊的工作方式是由配置文件指定,默認(rèn)情況下配置文件被命名為nginx.conf并且存放在/usr/local/nginx/conf或者 /etc/nginx或者 /usr/local/etc/nginx

默認(rèn)的config

#user nobody; worker_processes 1;#error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info;#pid logs/nginx.pid;events {worker_connections 1024; }http {include mime.types;default_type application/octet-stream;#log_format main '$remote_addr - $remote_user [$time_local] "$request" '# '$status $body_bytes_sent "$http_referer" '# '"$http_user_agent" "$http_x_forwarded_for"';#access_log logs/access.log main;sendfile on;#tcp_nopush on;#keepalive_timeout 0;keepalive_timeout 65;#gzip on;server {listen 80;server_name localhost;#charset koi8-r;#access_log logs/host.access.log main;location / {root html;index index.html index.htm;}#error_page 404 /404.html;# redirect server error pages to the static page /50x.html#error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {# proxy_pass http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {# root html;# fastcgi_pass 127.0.0.1:9000;# fastcgi_index index.php;# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;# include fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {# deny all;#}}# another virtual host using mix of IP-, name-, and port-based configuration##server {# listen 8000;# listen somename:8080;# server_name somename alias another.alias;# location / {# root html;# index index.html index.htm;# }#}# HTTPS server##server {# listen 443 ssl;# server_name localhost;# ssl_certificate cert.pem;# ssl_certificate_key cert.key;# ssl_session_cache shared:SSL:1m;# ssl_session_timeout 5m;# ssl_ciphers HIGH:!aNULL:!MD5;# ssl_prefer_server_ciphers on;# location / {# root html;# index index.html index.htm;# }#}}

nginx文件結(jié)構(gòu)

... #全局塊events { #events塊... }http #http塊 {... #http全局塊server #server塊{ ... #server全局塊location [PATTERN] #location塊{...}location [PATTERN] {...}}server{...}... #http全局塊 }

含義

1、全局塊:配置影響nginx全局的指令。一般有運(yùn)行nginx服務(wù)器的用戶組,nginx進(jìn)程pid存放路徑,日志存放路徑,配置文件引入,允許生成worker process數(shù)等。

2、events塊:配置影響nginx服務(wù)器或與用戶的網(wǎng)絡(luò)連接。有每個(gè)進(jìn)程的最大連接數(shù),選取哪種事件驅(qū)動(dòng)模型處理連接請(qǐng)求,是否允許同時(shí)接受多個(gè)網(wǎng)路連接,開啟多個(gè)網(wǎng)絡(luò)連接序列化等。

3、http塊:可以嵌套多個(gè)server,配置代理,緩存,日志定義等絕大多數(shù)功能和第三方模塊的配置。如文件引入,mime-type定義,日志自定義,是否使用sendfile傳輸文件,連接超時(shí)時(shí)間,單連接請(qǐng)求數(shù)等。

4、server塊:配置虛擬主機(jī)的相關(guān)參數(shù),一個(gè)http中可以有多個(gè)server。

5、location塊:配置請(qǐng)求的路由,以及各種頁(yè)面的處理情況。

配置文件示例

########### 每個(gè)指令必須有分號(hào)結(jié)束。################# #user administrator administrators; #配置用戶或者組,默認(rèn)為nobody nobody。 #worker_processes 2; #允許生成的進(jìn)程數(shù),默認(rèn)為1 #pid /nginx/pid/nginx.pid; #指定nginx進(jìn)程運(yùn)行文件存放地址 error_log log/error.log debug; #制定日志路徑,級(jí)別。這個(gè)設(shè)置可以放入全局塊,http塊,server塊,級(jí)別以此為:debug|info|notice|warn|error|crit|alert|emerg events {accept_mutex on; #設(shè)置網(wǎng)路連接序列化,防止驚群現(xiàn)象發(fā)生,默認(rèn)為onmulti_accept on; #設(shè)置一個(gè)進(jìn)程是否同時(shí)接受多個(gè)網(wǎng)絡(luò)連接,默認(rèn)為off#use epoll; #事件驅(qū)動(dòng)模型,select|poll|kqueue|epoll|resig|/dev/poll|eventportworker_connections 1024; #最大連接數(shù),默認(rèn)為512 } http {include mime.types; #文件擴(kuò)展名與文件類型映射表default_type application/octet-stream; #默認(rèn)文件類型,默認(rèn)為text/plain#access_log off; #取消服務(wù)日志 log_format myFormat '$remote_addr–$remote_user [$time_local] $request $status $body_bytes_sent $http_referer $http_user_agent $http_x_forwarded_for'; #自定義格式access_log log/access.log myFormat; #combined為日志格式的默認(rèn)值sendfile on; #允許sendfile方式傳輸文件,默認(rèn)為off,可以在http塊,server塊,location塊。sendfile_max_chunk 100k; #每個(gè)進(jìn)程每次調(diào)用傳輸數(shù)量不能大于設(shè)定的值,默認(rèn)為0,即不設(shè)上限。keepalive_timeout 65; #連接超時(shí)時(shí)間,默認(rèn)為75s,可以在http,server,location塊。upstream mysvr { server 127.0.0.1:7878;server 192.168.10.121:3333 backup; #熱備}error_page 404 https://www.baidu.com; #錯(cuò)誤頁(yè)server {keepalive_requests 120; #單連接請(qǐng)求上限次數(shù)。listen 4545; #監(jiān)聽端口server_name 127.0.0.1; #監(jiān)聽地址 location ~*^.+$ { #請(qǐng)求的url過濾,正則匹配,~為區(qū)分大小寫,~*為不區(qū)分大小寫。#root path; #根目錄#index vv.txt; #設(shè)置默認(rèn)頁(yè)proxy_pass http://mysvr; #請(qǐng)求轉(zhuǎn)向mysvr 定義的服務(wù)器列表deny 127.0.0.1; #拒絕的ipallow 172.18.5.54; #允許的ip } } }

上面是nginx的基本配置,需要注意的有以下幾點(diǎn):

1、1.$remote_addr 與$http_x_forwarded_for 用以記錄客戶端的ip地址; 2.$remote_user :用來記錄客戶端用戶名稱; 3.$time_local : 用來記錄訪問時(shí)間與時(shí)區(qū);4.$request : 用來記錄請(qǐng)求的url與http協(xié)議;5.$status : 用來記錄請(qǐng)求狀態(tài);成功是200, 6.$body_bytes_s ent :記錄發(fā)送給客戶端文件主體內(nèi)容大小;7.$http_referer :用來記錄從那個(gè)頁(yè)面鏈接訪問過來的; 8.$http_user_agent :記錄客戶端瀏覽器的相關(guān)信息;2、驚群現(xiàn)象:一個(gè)網(wǎng)路連接到來,多個(gè)睡眠的進(jìn)程被同事叫醒,但只有一個(gè)進(jìn)程能獲得鏈接,這樣會(huì)影響系統(tǒng)性能。3、每個(gè)指令必須有分號(hào)結(jié)束。

nginx命令

要啟動(dòng)nginx直接運(yùn)行nginx文件,啟動(dòng)后可以使用以下命令。

nginx -s [options]

例如,/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf(帶配置文件參數(shù)的啟動(dòng)nginx)

options參數(shù)可以是下面之一:

  • stop - 快速關(guān)機(jī)
  • quit - 優(yōu)雅的關(guān)機(jī) (等待工作進(jìn)程完成當(dāng)前請(qǐng)求的服務(wù)時(shí),停止nginx進(jìn)程)
  • reload- 重新加載配置文件 (當(dāng)nginx配置發(fā)生更改的時(shí)候,需要指定該命令才會(huì)生效。一旦主進(jìn)程收到該命令,它將首先檢查配置文件的語法正確性然后嘗試應(yīng)用新的配置,如果應(yīng)用成功,主進(jìn)程將會(huì)啟動(dòng)新的工作進(jìn)程的同時(shí)向舊工作進(jìn)程發(fā)送關(guān)閉請(qǐng)求,否則的話主進(jìn)程將回滾更改繼續(xù)使用舊的配置。當(dāng)舊進(jìn)程接收關(guān)閉命令,舊進(jìn)程會(huì)停止接收新的請(qǐng)求同時(shí)完成正在處理的請(qǐng)求,最后舊工作進(jìn)程退出)
  • reopen - 重新打開日志文件

查看nginx進(jìn)程的列表
ps -ax
該命令可以看到所有進(jìn)程包括進(jìn)程ID,默認(rèn)情況下主進(jìn)程的ID將寫入nginx.pid目錄,

如果需要正常關(guān)閉某個(gè)進(jìn)程,執(zhí)行命令:kill -s QUIT 進(jìn)程ID

參數(shù)詳解

sudo nginx #啟動(dòng) nginx nginx -s reload|reopen|stop|quit #重新加載配置|重啟|停止|退出 nginx -t #測(cè)試配置文件nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]-?,-h : 打開幫助信息 -v : 顯示版本信息并退出 -V : 顯示版本和配置選項(xiàng)信息,然后退出 -t : 檢測(cè)配置文件是否有語法錯(cuò)誤,然后退出 -q : 在檢測(cè)配置文件期間屏蔽非錯(cuò)誤信息 -s signal : 給一個(gè) nginx 主進(jìn)程發(fā)送信號(hào):stop(停止), quit(退出), reopen(重啟), reload(重新加載配置文件) -p prefix : 設(shè)置前綴路徑(默認(rèn)是:/usr/local/Cellar/nginx/1.2.6/-c filename : 設(shè)置配置文件(默認(rèn)是:/usr/local/etc/nginx/nginx.conf) -g directives : 設(shè)置配置文件外的全局指令

總結(jié)

以上是生活随笔為你收集整理的【Nginx】Nginx配置文件参数/启动参数详解;启动/停止/重新加载配置命令的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。