如何启动Nginx服务器
Nginx包含四个部分,分别是:
- 1、Nginx二进制文件,一般位于 /usr/sbin/nginx 目录下。
- 2、Nginx配置文件,一般位于 /etc/nginx/nginx.conf,此外还有针对不同的服务器的配置文件,位于/etc/nginx/conf.d/ 文件夹下。
- 3、访问日志文件:access.log。一般位于/var/log/nginx/host.access.log,具体位置可以到nginx的配置文件里查找到,文件名和文件地址可以自定义。
- 4、错误日志文件:error.log,记录nginx服务器访问出错的日志,其他特点同访问日志文件。
启动命令
第一种:
# nginx -c /etc/nginx/nginx.conf
第二种:
# service nginx start
第三种(centos7)
# systemctl start nginx.service
访问Nginx服务器
1、先在服务器上查看一下ip地址
[root@localhost opt]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.11.139 netmask 255.255.255.0 broadcast 192.168.11.255
inet6 fd21:cb25:29dd:0:bf3b:595e:72fe:e22a prefixlen 64 scopeid 0x0<global>
inet6 fe80::1b46:40c1:2ab:8d42 prefixlen 64 scopeid 0x20<link>
inet6 fd21:cb25:29dd::698 prefixlen 128 scopeid 0x0<global>
ether 00:0c:29:30:66:23 txqueuelen 1000 (Ethernet)
RX packets 613637 bytes 893062929 (851.6 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 93568 bytes 6345051 (6.0 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
.....
2、浏览器访问
http://192.168.11.139
其他常用命令
1、帮助命令查看全部参数
[root@localhost opt]# nginx -h
nginx version: nginx/1.14.2
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]
Options:
-?,-h : this help
-v : show version and exit
-V : show version and configure options then exit
-t : test configuration and exit
-T : test configuration, dump it and exit
-q : suppress non-error messages during configuration testing
-s signal : send signal to a master process: stop, quit, reopen, reload
-p prefix : set prefix path (default: /etc/nginx/)
-c filename : set configuration file (default: /etc/nginx/nginx.conf)
-g directives : set global directives out of configuration file
2、常用命令
#重载配置文件,修改配置文件必须重载才能生效
#nginx -s reload
#优雅的停止服务
#nginx -s quit
#立刻停止服务
#nginx -s stop
#查看版本
#nginx -v 或者nginx -V
#执行配置文件启动
# nginx -c /etc/nginx/nginx.conf