华为云CentOS8安装Nginx

在CentOS 8系统中安装Nginx


从CentOS 8开始,Nginx软件包在默认的CentOS存储库中可用。

在CentOS 8系统中安装Nginx只需输入以下命令即可:

$ sudo yum install nginx

参考:在RHEL 8/CentOS 8上安装LEMP(Nginx、MariaDB、PHP7.2)的方法。

安装完成后,使用以下命令启用并启动Nginx服务:

$ sudo systemctl enable nginx

$ sudo systemctl start nginx

要验证服务是否正在运行,请检查其状态:

$ sudo systemctl status nginx

或者

$sudo service nginx status

输出如下所示:

nginx.service - The nginx HTTP and reverse proxy server

Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)

Active: active (running) since Sun 2019-10-06 18:35:55 UTC; 17min ago


调整防火墙(Firewall)

FirewallD是Centos 8中的默认防火墙解决方案。

在安装过程中,Nginx使用预定义的规则创建防火墙服务文件,以允许访问HTTP(80)和HTTPS(443)端口。

使用以下命令永久打开必要的端口:

$ sudo firewall-cmd --permanent --zone=public --add-service=http

$ sudo firewall-cmd --permanent --zone=public --add-service=https

$ sudo firewall-cmd --reload

 

配置多个虚拟主机

 

upstream myServer {
server 47.111.166.87:8081;#设置tomcat端口
}

server {
listen 80;
server_name bk.dagoua.com;#后台域名
location / {
proxy_pass http://myServer;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 80;
server_name blog.dagoua.com;#前台域名

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
root /usr/local/nginx/html/dist;
try_files $uri $uri/ /index.html;
index index.html;
}
#跨域处理
location /api {
proxy_pass http://bk.dagoua.com/;

 

posted @ 2021-07-07 08:25  jamesben  阅读(464)  评论(0编辑  收藏  举报