添加yum源
默认情况Centos7中无Nginx的源,最近发现Nginx官网提供了Centos的源地址。因此可以如下执行命令添加源:
rpm -Uvh http://Nginx.org/packages/centos/7/noarch/RPMS/Nginx-release-centos-7-0.el7.ngx.noarch.rpm
安装Nginx
yum install -y Nginx
systemctl start Nginx.service
systemctl enable Nginx.service
- 开启Nginx服务后可以直接通过ip访问
http://ip 默认80端口
若无法访问 ,需要在iptable上添加80端口,如果用的阿里云或腾讯云还需要添加安全组
CentOS中iptables防火墙 开放80端口方法
- 开放端口
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
- 保存配置
service iptables save
- 重启防火墙
service iptables restart
- 查看配置
service iptables status
Nginx相关路径
问题总结
Job for Nginx.service Failed because the control process exited with error code. See "systemctl status Nginx.service" and "journalctl -xe" for details.
执行以下命令查看服务状态
systemctl status Nginx
Nginx.service - Nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/Nginx.service; disabled; vendor preset: disabled)
Active: Failed (Result: exit-code) since 四 2019-05-30 14:34:48 CST; 1min 35s ago
Docs: http://Nginx.org/en/docs/
Process: 6051 ExecStart=/usr/sbin/Nginx -c /etc/Nginx/Nginx.conf (code=exited, status=1/FAILURE)
Main PID: 1542 (code=killed, signal=KILL)
5月 30 14:34:45 iz2ze3bc56k6c8wubzxn9kz Nginx[6051]: Nginx: [emerg] bind() to 0.0.0.0:80 Failed (98: Address already in use)
5月 30 14:34:46 iz2ze3bc56k6c8wubzxn9kz Nginx[6051]: Nginx: [emerg] bind() to 0.0.0.0:80 Failed (98: Address already in use)
5月 30 14:34:46 iz2ze3bc56k6c8wubzxn9kz Nginx[6051]: Nginx: [emerg] bind() to 0.0.0.0:80 Failed (98: Address already in use)
5月 30 14:34:47 iz2ze3bc56k6c8wubzxn9kz Nginx[6051]: Nginx: [emerg] bind() to 0.0.0.0:80 Failed (98: Address already in use)
5月 30 14:34:47 iz2ze3bc56k6c8wubzxn9kz Nginx[6051]: Nginx: [emerg] bind() to 0.0.0.0:80 Failed (98: Address already in use)
5月 30 14:34:48 iz2ze3bc56k6c8wubzxn9kz systemd[1]: Nginx.service: control process exited, code=exited status=1
5月 30 14:34:48 iz2ze3bc56k6c8wubzxn9kz Nginx[6051]: Nginx: [emerg] still Could not bind()
5月 30 14:34:48 iz2ze3bc56k6c8wubzxn9kz systemd[1]: Failed to start Nginx - high performance web server.
5月 30 14:34:48 iz2ze3bc56k6c8wubzxn9kz systemd[1]: Unit Nginx.service entered Failed state.
5月 30 14:34:48 iz2ze3bc56k6c8wubzxn9kz systemd[1]: Nginx.service Failed.
可以看到以上错误是因为端口被占用的原因
查看Nginx服务
ps -ef | grep Nginx
杀死进程
pkill -9 Nginx
再启动就可以了
systemctl start Nginx
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。