windowsOS中nginx常用命令
验证nginx配置文件是否正确
nginx -t
配置文件修改后重载
nginx -s reload
查看nginx的版本号
nginx -V
启动nginx
start nginx
快速停止或关闭nginx服务
nginx -s stop
正常停止或关闭nginx服务
nginx -s quit
查看任务启动列表
tasklist /fi "imagename eq nginx.exe"
关闭nginx进程
taskkill -t -f /pid pid号
LinuxOS中nginx常用命令
启动 #使用默认的配置启动
sodu nginx
#指定配置启动 /etc/nginx/nginx.conf 替换为自己的配置
sudo nginx -c /etc/nginx/nginx.conf
#指定错误日志路径 /etc/nginx/error.log 替换为自己的配置
sudo nginx -e /etc/nginx/error.log
#查看运行进程
ps -ef|grep nginx
#关闭nginx进程
kill -QUIT pid进程号
#查看端口使用情况
netstat -ntlp|grep 80
nginx服务配置
server {
listen 80;
server_name localhost;
location / {
root /opt_web/dist; #页面在服务器的路径
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
location /api/ {
proxy_pass http://10.167.154.239:8000/
}
}
编辑nginx.conf文件
vim nginx.conf (e, i, :wq)
nginx服务配置常见问题
页面刷新nginx404
try_files $uri $uri/ /index.html
获取真实IP
proxy_set_header X-Real-IP $remote_addr
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for