這里寫自定義目錄標題
- 定義域名(本地)
- Nginx的一下常用命令記錄
- win系統使用 .bat來啟動
- nginx配置
定義域名(本地)
本地定義域名不需要證書,直接更改hosts文件。
注意:在這個文件夾中是無法更改hosts文件的,可以將hosts復制到桌面進行更改后再覆蓋原先的hosts文件
win路徑:C:\Windows\System32\drivers\etc
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host# localhost name resolution is handled within DNS itself.
127.0.0.1 localhost
# ::1 localhost
127.0.0.1 activate.navicat.com
127.0.0.1 ts5nginx.com
Nginx的一下常用命令記錄
啟動start nginx
關閉nginx.exe -s stop
強停taskkill /f /t /im nginx.exe
重啟()nginx -s reload
win系統使用 .bat來啟動
新建一個txt文本在txt文本中寫入啟動或關閉等命令,然后修改后綴名 .bat。在要使用某個命令時點擊一下就可以了。
注意:文本要建在nginx.exe同類目下
start nginx
nginx配置
#進程用戶
#user nobody;#工作進程,配合和CPU個數保持一致
worker_processes 2;#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;#pid logs/nginx.pid;events {#內核模型,select、poll、epoll#use epoll;#每個 worker process 可以同時支持的最大連接數等。worker_connections 1024;
}http {include mime.types;default_type application/octet-stream;# 日志打印的內容格式# 注釋時,默認打印的是 127.0.0.1 - - [23/May/2024:10:28:21 +0800] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"# 自定義后 會將請求頭,請求類型等打印出來#127.0.0.1 - - [23/May/2024:15:51:02 +0800] "POST /wxapi.php/Device/doGetStatus HTTP/1.1" 200 157 "http://ts5nginx.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"# 注意!!! 只使用這個log_format是無效的必須 access_log的路徑必須要寫否則還是默認的log_format access '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"''"$server_name"';# win 的log日志地址需要絕對路徑, 在http中定義那就是所有服務(server)的可以在每個服務(server)中單獨定義 access_logaccess_log C:/Work/nginx-1.26.0/logs/access.log;sendfile on;#tcp_nopush on;#keepalive_timeout 0;keepalive_timeout 65;#gzip on;server {# 80端口不可更改否則訪問時必須帶端口,例如81 正常:http://localhost/ 更改后:http://localhost:81/# 可能是因為防火墻的原因listen 80;#本地域名在hosts文件中添加。注意在這個文件夾中無法修改hosts文件需要復制一個文件到可修改的文件夾中進行修改然后復制回來覆蓋掉老的文件 C:\Windows\System32\drivers\etcserver_name ts5nginx.com;# 默認重定向 使用ts5nginx.com 來訪問就定向到C:/Work_file/tian/Web/tvue/dist中 并嘗試查找并返回匹配的文件。具體地說,它會首先查找index.php文件,如果不存在則查找index.html文件,如果還不存在則查找index.htm文件。# 注意路徑要絕對路徑,win與linux都是絕對路徑。win的路徑不能使用\斜杠root C:/Work_file/tian/Web/tvue/dist;index index.php index.html index.htm;# 將所有的訪問轉換成 http 正式就用 https://$host$request_uri 轉換成httpsreturn 301 http://$host$request_uri;#charset koi8-r;#access_log logs/host.access.log main;# 重定向到服務器的 8081服務(后端)location ^~/wxapi.php/ {proxy_pass http://localhost:8081;proxy_set_header Host $host$request_uri;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-Forwarded-Proto $scheme;root html;index index.html index.htm;}# 使用 ts5nginx.com/img.png 便可訪問服務器上的文件# 用于微信的域名證書驗證什么的 MP_verify_0EZJXnKP7GfACeli.txt# 例: location /MP_verify_0EZJXnKP7GfACeli.txt {# alias C:\Users\DELL\Pictures\MP_verify_0EZJXnKP7GfACeli.txt;# }location /img.png {alias C:\Users\DELL\Pictures\1715390062731.png;}# 默認報錯時展示的頁面error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}}
}