CentOS 8安装Nginx并配合Tomcat搭建反向服务器

######### 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 ## &lt-- start the server ##
#sudo systemctl stop nginx ## &lt-- stop the server ##
#sudo systemctl restart nginx ## &lt-- restart the server ##
#sudo systemctl reload nginx ## &lt-- reload the server ##
#sudo systemctl status nginx ## &lt-- 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/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值