asp.net Core 部署到CentOs7上,使用Nginx做代理

一、CentOs7部署Nginx

1、准备工作

       Nginx的安装依赖于以下三个包,意思就是在安装Nginx之前首先必须安装一下的三个包,注意安装顺序如下:

  1 SSL功能需要openssl库,直接通过yum安装: #yum install openssl

  2 gzip模块需要zlib库,直接通过yum安装: #yum install zlib

  3 rewrite模块需要pcre库,直接通过yum安装: #yum install pcre这个是在这篇博文 http://www.cnblogs.com/hanyinglong/p/5102141.html 

2、安装Nginx依赖项和Nginx

  1 使用yum安装nginx需要包括Nginx的库,安装Nginx的库

    #rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

  2 使用下面命令安装nginx

    #yum install nginx

  3 启动Nginx

    #service nginx start

 

  运行Nginx 

  命令:systemctl start nginx 来启动nginx。

                  或者 service nginx start

  命令:systemctl enable nginx 来设置nginx的开机启动(linux宕机、重启会自动运行nginx不需要连上去输入命令)。

                  或者chkconfig nginx on

        运行成功后可以进浏览器看一下Nginx是否能正常运行, 如果启动错误,根据提示查找错误原因,最可能的原因是80端口被占用了

        直接浏览器访问localhost就会出现Nginx的欢迎界面表示你安装成功了,否则就是安装失败了

3. 配置环境    

  1)配置防火墙

    命令:firewall-cmd --zone=public --add-port=80/tcp --permanent(开放80端口)

    命令:systemctl restart firewalld(重启防火墙以使配置即时生效)

  2)关闭SELinux ,使用getenforce 查询 

    临时关闭(不用重启机器):

      setenforce 0                  ##设置SELinux 成为permissive模式

      ##setenforce 1 设置SELinux 成为enforcing模式

    修改配置文件需要重启机器:

      修改/etc/selinux/config 文件

      将SELINUX=enforcing改为SELINUX=disabled

      重启机器即可

 

4. 修改Nginx的配置:etc/nginx/conf.d/default.conf     

server {
  listen 80;
  server_name localhost;
  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 $host;
    proxy_cache_bypass $http_upgrade;
  }
}

  

  重新加载Nginx配制文件

             命令:nginx -t 测试配制文件是否正确

             命令:nginx -s reload 重新加载nginx配制文件,不用重启nginx

  

 

posted @ 2018-08-17 11:13  蓝平凡  阅读(314)  评论(0编辑  收藏  举报