5、CentOS 7 yum 安装 NGINX
如果之前没有安装过 EPEL 源的需要安装。
安装 EPEL 源:
yum install epel-release
安装 Nginx:
yum install -y nginx
启用并启动 Nginx 服务:
systemctl enable nginx # 启用自启
systemctl start nginx # 启动
systemctl stop nginx # 停止
systemctl restart nginx # 重启
systemctl reload nginx # 重载
systemctl disable nginx # 禁用Nginx服务自启
打开端口80和443:
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
Nginx配置文件的结构和最佳实践
所有Nginx配置文件都位于/etc/nginx/目录中。
Nginx的主要配置文件是/etc/nginx/nginx.conf。
为了使Nginx配置更易于维护,建议为每个域创建一个单独的配置文件。
新的Nginx服务器阻止文件必须以结尾.conf并存储在/etc/nginx/conf.d目录中。您可以根据需要拥有任意数量的服务器块。
遵循标准的命名约定是一个好主意,例如,如果您的域名是,mydomain.com那么您的配置文件应命名为/etc/nginx/conf.d/mydomain.com.conf
如果您在域服务器块中使用可重复的配置段,则最好创建一个名为将/etc/nginx/snippets这些段重构为片段的目录,并将片段文件包括到服务器块中。
Nginx日志文件(access.log和error.log)位于/var/log/nginx/目录中。建议有不同access,并error为每个服务器模块的日志文件。
您可以将域文档的根目录设置为所需的任何位置。webroot的最常见位置包括:
/home//
/var/www/
/var/www/html/
/opt/
/usr/share/nginx/html
本作品采用《CC 协议》,转载必须注明作者和本文链接
nginx有官方源,速度有点慢,看官方文档,里面有安装步骤。