您现在的位置是:网站首页>编程语言

Centos 7.6 上部署NET CORE 3.1程序【Nginx安装配置篇】

编程语言阿文2021年1月14日2040浏览

简介Centos7.6上Nginx安装并配置步骤第一步安装(我用的云服务器直接用yum安装):yuminstallnginx-y第二步查看nginx是否运行:nginx-V#查看安装的nginx版本systemctlstartnginx#启动nginx……

Centos 7.6上Nginx安装并配置步骤

第一步安装(我用的云服务器直接用yum安装)

yum install nginx -y

第二步查看nginx是否运行

nginx -V  #查看安装的nginx版本
systemctl start nginx   #启动nginx
systemctl enable nginx  #设置nginx为开机启动

刚装好,发现启动失败了,不过我重启下服务器,发现又能正常启动了。。然后记得把防火墙关了 systemctl stop firewalld,输入服务器ip,发现ok了,

l6

不过外网环境防火墙还是需要的,安全点嘛。

第三步启动防火墙

这里我准备用到的端口是81端口

firewall-cmd --state #查看防火墙状态
systemctl start firewalld.service #启动防火墙
firewall-cmd --zone=public --add-port=81/tcp --permanent #永久增加81端口
firewall-cmd --reload #重新加载配置 
firewall-cmd --list-all #查看防火墙允许的端口地址
systemctl enable firewalld.service  #将防火墙加入开启自启动

以上我们开放了81端口,可以用telnet 测试端口是否可以访问

l7

第四步修改nginx配置文件

nginx默认安装后配置文件所在目录/etc/nginx/

cd /etc/nginx/ #进入配置文件目录

修改nginx.conf 文件,增加一个server

server {
        listen 81;
        location / {
            proxy_pass http://localhost:5000;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection keep-alive;
            proxy_set_header Host $http_host;
            proxy_cache_bypass $http_upgrade;
        }  
}

以上nginx配置说明(访问81端口就匹配到本地5000端口,5000端口是本地运行的netocre程序端口)

nginx -s reload #重新加载配置

我们检查nginx状态,如果未启动则再次启动

常用命令:

systemctl status nginx   #查询nginx状态
systemctl start nginx   #启动nginx
systemctl stop nginx    #停止nginx

我们再次浏览器测试IP+81端口访问发现还是访问不了,记得在服务器管理把81端口加入规则列表

111


nginx其他命令

systemctl start nginx.service (启动nginx服务)
systemctl stop nginx.service (停止nginx服务)
systemctl enable nginx.service (设置开机自启动)
systemctl disable nginx.service (停止开机自启动)
systemctl status nginx.service (查看服务当前状态)
systemctl restart nginx.service (重新启动服务)
systemctl list-units --type=service (查看所有已启动的服务)

Nginx开机自启动脚本配置nginx.service(此处留作笔记)

[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
# Nginx will fail to start if /run/nginx.pid already exists but has the wrong
# SELinux context. This might happen when running `nginx -t` from the cmdline.
# https://bugzilla.redhat.com/show_bug.cgi?id=1268621
ExecStartPre=/usr/bin/rm -f /run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID

KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true

[Install]
WantedBy=multi-user.target


标签: Centos

0

评论文明上网,理性发言0条评论