nginx操作
定位nginx
服務器上有多個nginx,定位當前正在運行的Nginx的配置文件
ps -ef | grep nginx #查看當前運行的nginx的位置
#1,查看nginx的PID,以常用的80端口爲例:
netstat -anop | grep 0.0.0.0:80
#2,通過相應的進程ID(比如:4562)查詢當前運行的nginx路徑:
ll /proc/4562/exe
#3. 獲取到nginx的執行路徑後,使用-t參數即可獲取該進程對應的配置文件路徑
/usr/local/nginx/sbin/nginx -t
#輸出以下
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
nginx命令
linux nginx啓動 重啓 關閉命令:
以下命令均要在響應目錄下運行或者全路徑下
home/odin/nginx/sbin/nginx -s reload #修改配置後重新加載生效
# 啓動操作 要啓動的nginx 的sbin目錄下
./nginx -s reload #修改配置後重新加載生效
#啓動操作 -c參數指定了要加載的nginx配置文件路徑
./nginx -c /usr/local/nginx/conf/nginx.conf
#重新打開日誌文件
./nginx -s reopen
#測試nginx配置文件是否正確
./nginx -t -c /path/to/nginx.conf
#停止nginx
nginx -s stop #快速停止nginx
quit #完整有序的停止nginx
#其他的停止nginx 方式:找到進程發送信號方式
#步驟1,查詢nginx主進程號
ps -ef | grep nginx
#步驟2:發送信號
kill -QUIT 16391 #從容停止Nginx:
kill -TERM 16391 #快速停止Nginx:
kill -9 16391 #強制停止Nginx:
附上配置文件
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#vhost文件夾下的多端口配置
include ./vhost/*.conf;
sendfile on;
server {
listen 8088;
server_name localhost;
location / {
root D:\WuWorkSpace\wu_project\wu_vueProject\mySGMpro\feature_v2_9_0dist;#文件目錄
try_files $uri $uri/ @router; #需要指向下面的@router否則會出現vue的路由在nginx中刷新出現404
index index.html;#默認起始頁
}
#對應上面的@router,主要原因是路由的路徑資源並不是一個真實的路徑,所以無法找到具體的文件
#因此需要rewrite到index.html中,然後交給路由在處理請求資源
location @router {
rewrite ^.*$ /index.html last;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
#location ~ /\.
#{
# deny all;
#}
}
}