Py学习  »  NGINX

CentOS yum源安装 Nginx

DoubleX • 3 年前 • 231 次点击  
阅读 6

CentOS yum源安装 Nginx

安装首要条件

确保以拥有sudo权限的用户来登录的服务器,并且服务中没有Apache或其他服务占用80和443端口上,防止端口被占用,Nginx无法正常启动

开始安装

  • 设置yum存储库,请创建/etc/yum.repos.d/nginx.repo包含以下内容的文件
[nginx] 
name=nginx repo 
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0 
enabled=1
复制代码
  • 开始安装Nginx
yum install nginx
复制代码
  • 设置Nginx开机启动
sudo systemctl enable nginx
复制代码

运行以上命令以后,会输出类似以下的内容,表示创建了一个软连接来关联Nginx,不用担心,并不是报错了,接下来就可以启动Nginx了。

Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
复制代码
  • 启动Nginx
sudo systemctl start nginx
复制代码
  • 查看Nginx状态
sudo systemctl status nginx
复制代码
  • 访问自己的IP就可以看到Nginx欢迎页面了,首次访问替换占用了80端口所以只需要输入IP地址即可

配置文件相关

  • 以上方式安装所有配置文件相关目录 /etc/nginx
  • Nginx主配置文件 /etc/nginx/nginx.conf
  • 日志文件目录 /var/log/nginx/
  • 默认静态资源目录 /usr/share/nginx/html/

systemctl管理Nginx

# 启动 nginx
sudo systemctl start nginx
# 关闭 nginx
sudo systemctl stop nginx
# 重启 nginx
sudo systemctl restart nginx
# 修改 nginx 配置后重新加载
sudo systemctl reload nginx
# 设置开机启动 nginx
sudo systemctl enable nginx
# 关闭开机启动 nginx
sudo systemctl disable nginx
# 查看 nginx 状态
sudo systemctl status nginx
复制代码

本文使用 mdnice 排版

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/63073
 
231 次点击