linux 下操作
1–查找nginx 的配置目录:
密令:locate nginx.conf
结果: /opt/nginx/conf/nginx.conf
2–测试nginx的配置文件是否正确:
密令: ./opt/nginx/sbin/nginx -t
3–重启nginx:
密令:./nginx -s reload
4–杀死进程
ps -ef | grep nginx
kill signal xx
基本用法:
start nginx //启动
nginx -s stop //停止
#代理到xxxxx域名
server {
listen 3005;
server_name localhost;
location / {
proxy_pass http://www.baidu.com;
}
}
#指向本地dist目录下的index.html
server {
listen 3002;
server_name localhost;
location / {
root /root/swagger/swagger-ui/dist;
index index.html;
}
}}
#路由匹配拦截,跳转到指定服务
server {
listen 3553;
server_name 127.0.0.1;
location /api {
proxy_pass http://localhost:3010/api;
}
}
如果出现403,可能需要再nginx.conf文件中,添加
user root;
如果提交的头文件字段 被拦截,例如:aa_token,则需要设置 underscores_in_headers 为on
underscores_in_headers on;