2.Nginx常用命令和配置文件

1.Nginx常用命令

(1)查看nginx版本号:
[root@localhost sbin]# ./nginx -v
nginx version: nginx/1.20.2
[root@localhost sbin]#
(2)关闭Nginx命令:
[root@localhost sbin]# ./nginx -s stop
[root@localhost sbin]# ps -ef | grep nginx
root 2615 2053 0 09:39 pts/1 00:00:00 grep --color=auto nginx
[root@localhost sbin]#
(3)启动Nginx命令:
[root@localhost sbin]# ./nginx
[root@localhost sbin]#
(4)重载配置命令:
备注:找到conf文件:
[root@localhost sbin]# cd /etc/nginx/
[root@localhost nginx]# ll
total 24
drwxr-xr-x. 2 root root 26 Apr 6 05:13 conf.d
-rw-r--r--. 1 root root 1007 Nov 16 10:03 fastcgi_params
-rw-r--r--. 1 root root 5231 Nov 16 10:03 mime.types
lrwxrwxrwx. 1 root root 29 Apr 6 05:13 modules -> ../../usr/lib64/nginx/modules
-rw-r--r--. 1 root root 648 Nov 16 10:02 nginx.conf
-rw-r--r--. 1 root root 636 Nov 16 10:03 scgi_params
-rw-r--r--. 1 root root 664 Nov 16 10:03 uwsgi_params
(5)关闭nginx:
找到pid:
[root@localhost run]# pwd
/var/run
[root@localhost run]#
或者:
[root@localhost run]# ps -ef | grep nginx
root 2617 1 0 09:40 ? 00:00:00 nginx: master process ./nginx
nginx 2622 2617 0 09:41 ? 00:00:00 nginx: worker process
root 2628 2053 0 09:48 pts/1 00:00:00 grep --color=auto nginx
执行:
[root@localhost run]# kill -s QUIT 2617
(6)优雅的停止nginx:
# 启动nginx:
[root@localhost run]# /usr/sbin/nginx
[root@localhost run]# ps -ef | grep nginx
root 2632 1 0 09:50 ? 00:00:00 nginx: master process /usr/sbin/nginx
nginx 2633 2632 0 09:50 ? 00:00:00 nginx: worker process
root 2635 2053 0 09:50 pts/1 00:00:00 grep --color=auto nginx
# 优雅停止nginx
[root@localhost run]# /usr/sbin/nginx -s quit
[root@localhost run]# ps -ef | grep nginx
root 2638 2053 0 09:51 pts/1 00:00:00 grep --color=auto nginx


2.配置文件介绍

找到nginx配置文件:/etc/nginx
指令种类:简单指令,块指令。
全局块:就是最开始的简单指令。从配置文件开始到events
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events块:配置服务器和用户网络连接相关的参数。
http块:
http {
         include /etc/nginx/mime.types;
         default_type application/octet-stream;
         log_format main '$remote_addr - $remote_user [$time_local] "$request" '
         '$status $body_bytes_sent "$http_referer" '
         '"$http_user_agent" "$http_x_forwarded_for"';
         access_log /var/log/nginx/access.log main;
         sendfile on;
         #tcp_nopush on;
         keepalive_timeout 65;
         #gzip on;
         include /etc/nginx/conf.d/*.conf;
         # server块可以是 多个
         server {
         listen 80;
         # server_name 127.0.0.1;
         server_name www.cpf.com;
         # location 块可以是 多 个
         location / {
         proxy_pass http://127.0.0.1:8080;
         }
 }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值