美文网首页
nginx配置反向代理

nginx配置反向代理

作者: Daisy小朋友 | 来源:发表于2019-05-28 14:57 被阅读0次

    前提:为了安全将zabbix配置在内网中,实现将nginx放在前端,通过域名访问

    环境:
    Linux: Centos7.2
    nginx:nginx1.14.2
    证书及域名:阿里云域名以及证书

    1.源码安装nginx,普通用户nginx启动

    第三方模块需要编译才可以,需要安装依赖包:

    yum -y install pcre-devel openssl openssl-devel
    

    在vim中修改nginx配置与法

    mkdir ~/.vim
    cp -r contrib/vim/* ~/.vim/
    

    下载相应的源码包nginx-1.14.2.tar.gz

    tar -xzf nginx-1.14.2.tar.gz
    cd /nginx/nginx-1.14.2 && ./configure —prefix=/data && make&&make install 
    

    2.启动和停止

    启动

    /nginx/sbin/nginx
    

    停止

    /nginx/sbin/nginx -s stop
    

    重启

    /nginx/sbin/nginx -s reload
    

    3.配置https

    访问域名:zabbix.changhuanyan.pub
    https:10443端口 因为普通用户不可使用1024以下端口,所以这使用10443端口,再从防火墙做端口转发到443
    http:9000 端口 因为普通用户不可使用1024以下端口,所以这使用9000端口,再从防火墙做端口转发到80
    证书:/nginx/conf/test_cert/changhuanyan.pub.pem && /nginx/conf/test_cert/changhuanyan.pub.key
    跳转的内网应用地址:http://10.xx.xxx.xx/zabbix/;

    确保vim /nginx/conf/nginx.conf中包含include conf.d/*.conf;
    cd /nginx/conf/conf.d
    -bash-4.2$ cat zabbix.conf
    server {
        listen 10443;
        server_name zabbix.changhuanxxxan.pub;       
        ssl on;
        ssl_certificate /nginx/conf/test_cert/changhuanyan.pub.pem;
        ssl_certificate_key  /nginx/conf/test_cert/changhuanyan.pub.key;
        ssl_session_timeout 5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
        ssl_prefer_server_ciphers on;
        access_log /nginx/logs/zabbix.access.log;
        error_log  /nginx/logs/zabbix.error.log;
    
        location / {
            client_max_body_size 100m;
            proxy_set_header X-Forwarded-Host $host;
            proxy_set_header X-Forwarded-Server $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_connect_timeout 60s;
            proxy_redirect  http:// https://;
            proxy_pass http://10.xx.xxx.xx/zabbix/;
        }
    
    }
    
    server {
        listen 9000;
        server_name zabbix.changhuanxxxan.pub;
        rewrite ^(.*) https://$server_name$1;
    }
    

    防火墙端口转发80->9000 443->10443,centos7
    防火墙设置可以参考: https://www.jianshu.com/p/41ca6a6f042a

    firewall-cmd --add-forward-port=port=80:proto=tcp:toport=9000 --permanent
    firewall-cmd --add-forward-port=port=443:proto=tcp:toport=10443 --permanent
    firewall-cmd --reload
    

    4.云主机域名及证书申请

    申请域名可以直接在云控制台申请,申请完毕后需要实名认证,也需要备案,域名才可以正常使用。
    证书申请有云控制台有免费的证书可以申请,如阿里云控制台


    image.png
    image.png

    注意可以使用二级域名,zabbix.changtest.com


    image.png

    相关文章

      网友评论

          本文标题:nginx配置反向代理

          本文链接:https://www.haomeiwen.com/subject/pufdtctx.html