# nginx - 常用命令
# 启动和关闭
- 利用配置文件启动 nginx:
nginx -c /usr/local/nginx/conf/nginx.conf
- 重启服务:
service nginx restart
- 快速停止或关闭 nginx:
nginx -s stop
- 正常停止或关闭 nginx:
nginx -s quit
- 配置文件修改重装载命令:
nginx -s reload
# 查找和删除 nginx
- 查看 nginx 的运行情况
ps -ef | grep nginx
[root@localhost /]# ps -ef |grep nginx
root 3163 2643 0 14:08 tty1 00:00:00 man nginx
root 5427 1 0 14:50 ? 00:00:00 nginx: master process nginx
nginx 5428 5427 0 14:50 ? 00:00:00 nginx: worker process
root 5532 2746 0 14:52 pts/0 00:00:00 grep --color=auto nginx
1
2
3
4
5
2
3
4
5
whereis nginx
[root@localhost /]# whereis nginx
nginx: /usr/sbin/nginx /usr/lib64/nginx /etc/nginx /usr/share/nginx /usr/share/man/man8/nginx.8.gz /usr/share/man/man3/nginx.3pm.gz
1
2
2
find / -name nginx
[root@localhost /]# find / -name nginx
/usr/lib64/perl5/vendor_perl/auto/nginx
/usr/lib64/nginx
/usr/share/nginx
/usr/sbin/nginx
/etc/logrotate.d/nginx
/etc/nginx
/var/lib/nginx
/var/log/nginx
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
- 依次删除find查找到的所有目录:
rm -rf /usr/sbin/nginx
# 配置
修改转发请求大小限制
#web端接口
location /api/ {
# 转发
proxy_pass http://www.example.com/api/;
# 文件大小
client_max_body_size 100m;
}
1
2
3
4
5
6
7
2
3
4
5
6
7
修改请求 host,需要携带请求域名的时候(做了负载均衡)
#web端接口
location /api/ {
# 转发
proxy_pass http://www.example.com/api/;
# 修改 host 为网站域名
proxy_set_header Host $host;
}
1
2
3
4
5
6
7
2
3
4
5
6
7
url 修改规则
# 第一步,把所有的 mysite.com/api/interface 转换成: mysite.com/interface
location /api {
rewrite ^(.*)\/api(.*)$ $1$2;
}
# 第二步, 把所有的 mysite.com/interface 的请求,转发到 www.example.com/interface
location /interface {
proxy_pass http://www.example.com;
}
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9