nginx安装及启动
1.用yum源安装,首先配置yum源 在“/etc/yum.repo.d/”下创建yum源文件
例如:cd /etc/yum.repo.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
2.查看yum源包
yum info nginx 查看nginx安装包源信息版本等
yum install nginx 安装yum源安装包
安装完成后用”nginx -h” 查看nginx应用的命令
[root@ ~]# nginx -h
nginx version: nginx/1.16.
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
3.用”nginx”命令启动nginx服务
启动服务后用命令ss -ntlp查看端口和服务的情况
[root@ ~]# ss -ntlp
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN *: *:* users:(("rpcbind",pid=,fd=))
LISTEN 0 128 *:80 *:* users:(("nginx",pid=6044,fd=6),("nginx",pid=6043,fd=6),("nginx",pid=5797,fd=6))
LISTEN 192.168.122.1: *:* users:(("dnsmasq",pid=,fd=))
LISTEN *: *:* users:(("sshd",pid=,fd=))
LISTEN 127.0.0.1: *:* users:(("cupsd",pid=,fd=))
LISTEN 127.0.0.1: *:* users:(("sshd",pid=,fd=))
LISTEN ::: :::* users:(("rpcbind",pid=,fd=))
LISTEN ::: :::* users:(("sshd",pid=,fd=))
LISTEN ::: :::* users:(("cupsd",pid=,fd=))
LISTEN ::: :::* users:(("sshd",pid=,fd=))
4.再开通防火墙和80端口即可
firewall-cmd --zone=public --add-port=/tcp --permanent
firewall-cmd --reload
5用其他主机访问IP地址即可