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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Nginx >内容正文

Nginx

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

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

nginx配置文件

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

默認的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文件結構

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

含義

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

2、events塊:配置影響nginx服務器或與用戶的網絡連接。有每個進程的最大連接數,選取哪種事件驅動模型處理連接請求,是否允許同時接受多個網路連接,開啟多個網絡連接序列化等。

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

4、server塊:配置虛擬主機的相關參數,一個http中可以有多個server。

5、location塊:配置請求的路由,以及各種頁面的處理情況。

配置文件示例

########### 每個指令必須有分號結束。################# #user administrator administrators; #配置用戶或者組,默認為nobody nobody。 #worker_processes 2; #允許生成的進程數,默認為1 #pid /nginx/pid/nginx.pid; #指定nginx進程運行文件存放地址 error_log log/error.log debug; #制定日志路徑,級別。這個設置可以放入全局塊,http塊,server塊,級別以此為:debug|info|notice|warn|error|crit|alert|emerg events {accept_mutex on; #設置網路連接序列化,防止驚群現象發生,默認為onmulti_accept on; #設置一個進程是否同時接受多個網絡連接,默認為off#use epoll; #事件驅動模型,select|poll|kqueue|epoll|resig|/dev/poll|eventportworker_connections 1024; #最大連接數,默認為512 } http {include mime.types; #文件擴展名與文件類型映射表default_type application/octet-stream; #默認文件類型,默認為text/plain#access_log off; #取消服務日志 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為日志格式的默認值sendfile on; #允許sendfile方式傳輸文件,默認為off,可以在http塊,server塊,location塊。sendfile_max_chunk 100k; #每個進程每次調用傳輸數量不能大于設定的值,默認為0,即不設上限。keepalive_timeout 65; #連接超時時間,默認為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; #錯誤頁server {keepalive_requests 120; #單連接請求上限次數。listen 4545; #監聽端口server_name 127.0.0.1; #監聽地址 location ~*^.+$ { #請求的url過濾,正則匹配,~為區分大小寫,~*為不區分大小寫。#root path; #根目錄#index vv.txt; #設置默認頁proxy_pass http://mysvr; #請求轉向mysvr 定義的服務器列表deny 127.0.0.1; #拒絕的ipallow 172.18.5.54; #允許的ip } } }

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

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

nginx命令

要啟動nginx直接運行nginx文件,啟動后可以使用以下命令。

nginx -s [options]

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

options參數可以是下面之一:

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

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

如果需要正常關閉某個進程,執行命令:kill -s QUIT 進程ID

參數詳解

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

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。