######### Overview ##########
#Search for Nginx package:
sudo yum search nginx
#Install nginx package using the yum command on CentOS 8:
sudo yum update
sudo yum install nginx
#Update firewall settings and open TCP port 80 and 443. Run:
sudo firewall-cmd --permanent --zone=public --add-service=https --add-service=http
sudo firewall-cmd --reload
######### DETAILS ##########
######### 详细步骤参考以下命令 ##########
#Step 1 Update the system
#步骤1 更新系统
#Keeping your system, kernel, and the installed application is an essential sysadmin task.
#So update the system, run:
sudo yum updateinfo
sudo yum update
sudo reboot
#Step 2 Search for Nginx package
#步骤2 寻找可下载的nginx包
sudo yum search nginx
sudo yum list nginx
#Get Nginx version information that you are going to install, execute:
#查询即将下载的nginx包版本信息
sudo yum info nginx
#Step 3 Install Nginx on CentOS 8
#步骤3 安装Nginx
sudo yum install nginx
#Step 4 Enable nginx server
#步骤4 使nginx服务器有效
sudo systemctl enable nginx
#Run command as per your needs.
#nginx可选命令行
#sudo systemctl start nginx ## <-- start the server ##
#sudo systemctl stop nginx ## <-- stop the server ##
#sudo systemctl restart nginx ## <-- restart the server ##
#sudo systemctl reload nginx ## <-- reload the server ##
#sudo systemctl status nginx ## <-- get status of the server ##
#Start the service, run:
#启动服务器
sudo systemctl start nginx
#Step 5 Open port 80 and 443 using firewall-cmd
#步骤5 打开80和443端口,permanent代表永久,http.https代表80,443端口。打开后重新加载防火墙
sudo firewall-cmd --permanent --zone=public --add-service=http --add-service=https
sudo firewall-cmd --reload
sudo firewall-cmd --list-services --zone=public
#Step 6 Test it
#步骤 6 测试,运行以下command查看80,443端口是否启动
#Verify that port 80 or 443 opened using ss command command:
sudo ss -tulpn
#Step 7 Configure Nginx server
#步骤7 配置服务器,配置文件目录如下
#CentOS 8 Nginx Config directory - /etc/nginx/
#Master/Global config file - /etc/nginx/nginx.conf
#TCP ports opened by Nginx - 80 (HTTP), 443 (HTTPS)
#Document root directory - /usr/share/nginx/html
#To edit files use a text editor such as vi command/nano command:
#编辑配置文件
sudo vi /etc/nginx/nginx.conf
#修改http块
server {
listen 443 ssl; #监听443端口
server_name example.com; #公网域名
ssl_certificate /etc/nginx/ssl/example.com.crt; #绑定ssl证书
ssl_certificate_key /etc/nginx/ssl/example.com.key; #绑定ssl证书
ssl_session_cache shared:SSL:1m;
ssl_prefer_server_ciphers on;
}
server {
listen 80; #监听80端口
server_name example.com; #公网域名
# Redirect all HTTP requests to HTTPS
# 重定向至443端口
location / {
return 301 https://$server_name$request_uri;
}
}
#更多详细请参考如下url
#https://docs.nginx.com/nginx/deployment-guides/load-balance-third-party/apache-tomcat/