Nginx安装配置

date
May 18, 2022
slug
rebnpmcs
status
Published
tags
Nginx
summary
type
Post
 

安装

Centos

$ yum install nginx # 安装系统记录的版本

# 或使用repo文件,根据需要选择下面版本。保存内容需执行一次 yum update
$ vim /etc/yum.repos.d/nginx.repo

$ yum info nginx # 查看 可安装/已安装 nginx的版本信息
$ systemctl enable nginx.service # 配置开机启动
$ systemctl start nginx.service # 启动 nginx
版本一:不推荐!来自官方
[nginx]
name=nginx repo
baseurl=https://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
版本二:最新稳定版,推荐!!!
[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
版本三:最新主线版
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

Mac

$ brew install nginx // 安装

$ brew services start nginx // 启动

$ brew services stop nginx // 停止

$ brew services restart nginx // 重启nginx

$ nginx -s reload // 重新加载配置文件

$ nginx -t // 验证nginx配置文件是否正确

$ /usr/local/etc/nginx/nginx.conf // 配置文件位置

配置

开机启动
[Unit]
Description=nginx
After=network.target
  
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
  
[Install]
WantedBy=multi-user.target
 
systemctl enable nginx.service
systemctl status nginx.service
systemctl restart nginx.service
 

参考资料:
 

© 刘德华 2020 - 2023