方式1
1) netstat -anop | grep 0.0.0.0:80 查看nginx的pid
2) ll /proc/4562/exe nginx運行的路徑(好比查詢到: /usr/sbin/nginx)
3) /usr/sbin/nginx -t 查詢nginx中nginx.conf文件位置
方式2
nginx -t 直接查看位置javascript
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
驗證配置是否正確: nginx -t (也能查詢nginx.conf配置文件位置) 查看Nginx的版本號:nginx -V 啓動Nginx:start nginx 快速中止或關閉Nginx:nginx -s stop 正常中止或關閉Nginx:nginx -s quit 配置文件修改重裝載命令:nginx -s reload(經常使用) 查看最後30行錯誤日誌: tail -n30 /var/log/nginx/error.log
# 每行代碼必須;結束 # 全局塊 # nginx進程pid存放路徑,日誌存放路徑,配置文件引入,容許生成worker process數等 events { # events塊 # 配置影響nginx服務器或與用戶的網絡鏈接。有每一個進程的最大鏈接數,選取哪一種事件驅動模型處理鏈接請求,是否容許同時接受多個網路鏈接,開啓多個網絡鏈接序列化等。 } http { # http全局塊 # 能夠嵌套多個server,配置代理,緩存,日誌定義等絕大多數功能和第三方模塊的配置。如文件引入,mime-type定義,日誌自定義,是否使用sendfile傳輸文件,鏈接超時時間,單鏈接請求數等 # 查看某個url有沒有開啓gzip # curl -H "Accept-Encoding: gzip" -I url地址 使用這個命令能夠查看是否開啓gzip # 舉例 # curl -H "Accept-Encoding: gzip" -I http://47.100.11.151 這個是沒有開啓gzip # HTTP/1.1 200 OK # Server: nginx/1.10.2 # Date: Fri, 21 Jun 2019 22:49:09 GMT # Content-Type: text/html # Content-Length: 838 # Last-Modified: Sat, 16 Feb 2019 09:31:24 GMT # Connection: keep-alive # ETag: "5c67d86c-346" # Accept-Ranges: bytes # curl -H "Accept-Encoding: gzip" -I https://www.jd.com 這個是開啓gzip(Content-Encoding: gzip) # HTTP/1.1 200 OK # Server: JDWS/2.0 # Date: Fri, 21 Jun 2019 22:49:50 GMT # Content-Type: text/html; charset=utf-8 # Content-Length: 30026 # Connection: keep-alive # Vary: Accept-Encoding # Expires: Fri, 21 Jun 2019 22:50:11 GMT # Cache-Control: max-age=30 # Content-Encoding: gzip # ser: 4.129 # Via: BJ-Y-NX-112(HIT), http/1.1 HZ-CT-1-JCS-25 ( [cRs f ]) # Age: 0 # Strict-Transport-Security: max-age=7776000 # 開啓gzip功能, 該功能可放在 http{},server{},location{}中, 優先級別 location > server > http gzip on; # 開啓該功能 gzip_min_length 1k; # 小於1k的文件將不會被gzip gzip_comp_level 2; # 壓縮級別,1-9,數字越大,文件壓縮比越高,壓縮的越好 # 如下文件類型將會被壓縮, text/html不用設置,只要開啓,默認都會被壓縮 gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png font/ttf font/otf image/svg+xml; gzip_vary on; # 是否在http header中添加Vary: Accept-Encoding,建議開啓 gzip_disable "MSIE [1-6]\."; # 在IE6中禁用gzip server { # server全局塊,作端口的監聽 # server塊:配置虛擬主機的相關參數,一個http中能夠有多個server location [path] { # location塊 } location [path] { } # nginx配置請求轉發 # 雲服務器IP: http://47.100.11.151 # 第三方API: http://t.weather.sojson.com/api/weather/city/101030100 # 跨域解決: # 配置1) proxy_pass http://t.weather.sojson.com/api/ # 當訪問http://47.100.11.151/api/weather/city/101030100,其實就是訪問http://t.weather.sojson.com/api/weather/city/101030100 # 配置2) proxy_pass參數 http://t.weather.sojson.com 最後沒有/ # 訪問 http://47.100.11.151/api/weather/city/101030100,其實就是訪問http://t.weather.sojson.com/api/weather/city/101030100 # 推薦使用配置2 location /api/ { proxy_pass http://t.weather.sojson.com/api/; } } }