• nginx配置示例-含反向代理


    events {
        worker_connections  1024;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        server {
            listen 443 ssl http2;
            server_name teamemory.fun www.teamemory.fun;
            root /data/wwwroot/auctionPort;#项目路径
            charset utf-8;
            ssl_certificate    /data/3189862_www.teamemory.fun.pem;#.pem证书路径
            ssl_certificate_key  /data/3189862_www.teamemory.fun.key;#.key证书路径
            ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
            ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
            ssl_prefer_server_ciphers on;
            ssl_session_cache shared:SSL:10m;
            ssl_session_timeout 10m;
            error_page 497  https://$host$request_uri;
            location / {
               include uwsgi_params;
               uwsgi_pass 127.0.0.1:8997;
               uwsgi_param UWSGI_SCRIPT auctionPort.wsgi;
               uwsgi_param UWSGI_CHDIR /data/wwwroot/auctionPort/;#项目路径
               
            }
            location /static/ {
            alias /data/wwwroot/auctionPort/static/; #静态资源路径
            }
            access_log  /data/wwwroot/auctionPort/www.teamemory.fun.log;
            error_log  /data/wwwroot/auctionPort/www.teamemory.fun.error.log;
        }
        server {
            listen 80;
            server_name teamemory.fun www.teamemory.fun;
            root /opt/zj;
        }
    }

    以上配置的80端口和443端口完全是两套内容。通过http:teamemory.fun  和 https://teamemory.fun 分别可以查看。

    注意:谷歌浏览器默认会跳转到https的情况。

    events {
        worker_connections  1024;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        server {
            listen 443 ssl http2;
            server_name teamemory.fun www.teamemory.fun;
            root /data/wwwroot/auctionPort;#项目路径
            charset utf-8;
            ssl_certificate    /data/3189862_www.teamemory.fun.pem;#.pem证书路径
            ssl_certificate_key  /data/3189862_www.teamemory.fun.key;#.key证书路径
            ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
            ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
            ssl_prefer_server_ciphers on;
            ssl_session_cache shared:SSL:10m;
            ssl_session_timeout 10m;
            error_page 497  https://$host$request_uri;
            location / {
               include uwsgi_params;
               uwsgi_pass 127.0.0.1:8997;
               uwsgi_param UWSGI_SCRIPT auctionPort.wsgi;
               uwsgi_param UWSGI_CHDIR /data/wwwroot/auctionPort/;#项目路径
               
            }
            location /static/ {
            alias /data/wwwroot/auctionPort/static/; #静态资源路径
            }
            access_log  /data/wwwroot/auctionPort/www.teamemory.fun.log;
            error_log  /data/wwwroot/auctionPort/www.teamemory.fun.error.log;
        }
        server {
            listen 80;
            server_name teamemory.fun www.teamemory.fun;
            rewrite ^(.*) https://$server_name$1 permanent;  #代表重定向到443
        }
    
    }

    以上配置,无论你访问http:teamemory.fun  还是 https://teamemory.fun 均跳转到443对应的网页。

    events {
        worker_connections  1024;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        server {
            listen 443 ssl http2;
            server_name teamemory.fun www.teamemory.fun;
            root /data/wwwroot/auctionPort;#项目路径
            charset utf-8;
            ssl_certificate    /data/3189862_www.teamemory.fun.pem;#.pem证书路径
            ssl_certificate_key  /data/3189862_www.teamemory.fun.key;#.key证书路径
            ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
            ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
            ssl_prefer_server_ciphers on;
            ssl_session_cache shared:SSL:10m;
            ssl_session_timeout 10m;
            error_page 497  https://$host$request_uri;
            location / {
               include uwsgi_params;
               uwsgi_pass 127.0.0.1:8997;
               uwsgi_param UWSGI_SCRIPT auctionPort.wsgi;
               uwsgi_param UWSGI_CHDIR /data/wwwroot/auctionPort/;#项目路径
               
            }
            location /static/ {
            alias /data/wwwroot/auctionPort/static/; #静态资源路径
            }
            access_log  /data/wwwroot/auctionPort/www.teamemory.fun.log;
            error_log  /data/wwwroot/auctionPort/www.teamemory.fun.error.log;
        }
        server {
            listen 80;
            server_name teamemory.fun www.teamemory.fun;
            location / {
                proxy_pass http://localhost:7001;
            }
        }
    }

    以上是80端口反向代理到7001端口,相当于表面访问的是80端口,实际访问到了7001端口。

    events {
        worker_connections  1024;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        server {
            listen 443 ssl http2;
            server_name teamemory.fun www.teamemory.fun;
            root /data/wwwroot/auctionPort;#项目路径
            charset utf-8;
            ssl_certificate    /data/3189862_www.teamemory.fun.pem;#.pem证书路径
            ssl_certificate_key  /data/3189862_www.teamemory.fun.key;#.key证书路径
            ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
            ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
            ssl_prefer_server_ciphers on;
            ssl_session_cache shared:SSL:10m;
            ssl_session_timeout 10m;
            error_page 497  https://$host$request_uri;
            location / {
               include uwsgi_params;
               uwsgi_pass 127.0.0.1:8997;
               uwsgi_param UWSGI_SCRIPT auctionPort.wsgi;
               uwsgi_param UWSGI_CHDIR /data/wwwroot/auctionPort/;#项目路径
               
            }
            location /static/ {
            alias /data/wwwroot/auctionPort/static/; #静态资源路径
            }
            access_log  /data/wwwroot/auctionPort/www.teamemory.fun.log;
            error_log  /data/wwwroot/auctionPort/www.teamemory.fun.error.log;
        }
        server {
            listen 80;
            server_name teamemory.fun www.teamemory.fun;
            location / {  #匹配前端的地址
                root        /opt/zj/;
                try_files   $uri $uri/ /index.html last; //这里同时解决了vue的history模式,没有了 /#/
                index       index.html;
            }
            location /admin {  #匹配接口的地址
                proxy_pass http://localhost:7001;
            }
        }
    }

     以上的配置,我们可以看出,前后端分离,前端后台的项目部署是分开的,利用nginx的反向代理来进行配置。

    /usr/local/nginx/sbin/nginx -s reload   #nginx重启
  • 相关阅读:
    LA3523 二分图和点双连通分量的综合性质及证明
    LA4127计算几何+离散化+点覆盖
    LA 4728凸包算法-旋转卡壳的直径
    UVA 11168凸包+距离公式
    UVA 10652凸包+面的旋转
    UVA10969计算几何+交叉圆形成的圆弧长
    LA3485二分+求解积分方程+辛普森算法计算积分
    LA5009三分法
    UVA10341幂函数零点的通解分析
    UVA11524构造系数数组+高斯消元解异或方程组
  • 原文地址:https://www.cnblogs.com/teamemory/p/13217581.html
Copyright © 2020-2023  润新知