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;
}
}
}