参考http://chaishiwei.com/blog/1281.html 按下面步骤安装ngnix服务器
1. 添加 Nginx 的下载源到 yum
sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
2.用 yum 命令来安装 Nginx
sudo yum install -y nginx
- 命令
sudo systemctl start nginx.service //启动
# 开启 Nginx
service nginx start
# 停止 Nginx
service nginx stop
# 重启 Nginx
service nginx restart
# 查看 Nginx 状态
service nginx status
4.设置开机自启动
sudo systemctl enable nginx
5.遇到问题 Failed to read PID from file /var/run/nginx.pid: Invalid argument
解决办法:
mkdir -p /etc/systemd/system/nginx.service.d
printf "[Service]\nExecStartPost=/bin/sleep 0.1\n" > /etc/systemd/system/nginx.service.d/override.conf
systemctl daemon-reload
systemctl restart nginx.service
6.ipconfig 获取服务器ip,然后在/etc/nginx/conf.d/default.conf 里面修改 serve_name 为“服务器ip”,并再地址栏输入地址。即可访问。