使用Nginx配置SSL以及部署前端项目

简介: 本文介绍了如何使用Nginx配置SSL证书以启用HTTPS,并展示了如何通过Nginx部署前端项目,包括配置SSL证书、设置代理和负载均衡的示例。

简单记录一下使用Nginx配置SSL以及部署前端项目

1、配置SSL

openssl pkcs12 -in cert.pfx -nodes -out cert.pem
cd /home/senwill-back/first_project/
ls
sh app.sh status
cd /etc/nginx/
ls
openssl pkcs12 -in cert.pfx -nodes -out cert.pem
cd /usr/lib/ssl
ls
cp openssl.cnf openssl.old.cnf
cd /usr/local/openssl/ssl/
ls
cp openssl.cnf /usr/lib/ssl/
openssl pkcs12 -in cert.pfx -nodes -out cert.pem
cd /etc/nginx
pwd
ls
openssl pkcs12 -in cert.pfx -nodes -out cert.pem
pwd
ls
openssl pkcs12 -in cert.pfx -nodes -out cert.pem
openssl rsa -in cert.pem -out cert.key
cd /usr/sbin/
ls
./nginx -t
pwd
cd /etc/nginx/
openssl x509 -in cert.pem -out cert.crt
cd /usr/sbin
ls
./nginx -t
./nginx -s reload

2、配置文件(nginx.conf)


#user  nobody; //设置使用Nginx服务的系统用户
user  root;
worker_processes  1; //工作进程数

#error_log  logs/error.log; //全局错误日志定义类型
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid; //Nginx服务启动时的pid


events {
    //事件模块
    worker_connections  1024; //每个进程允许最大连接数
}


http {
   
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65; //服务端超时时间

    #gzip  on;

    # 80端口的服务
    server {
   
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
   
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        # 
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
   
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
   
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
   
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
   
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
   
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
   
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
   
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
   
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

    # 443端口的服务
    server {
   
        listen       443 ssl;
        server_name  example.com;

        ssl_certificate      cert.crt;
        ssl_certificate_key  cert.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

        location ^~ /senwill/project_1/api {
   
            proxy_pass https://IP_1:Port_1;
            // 设置链接超时时间为3800秒
            proxy_read_timeout  3800s;
            proxy_connect_timeout 3800s;
            proxy_send_timeout 3800s;
            send_timeout 3800s;
        }

        location ^~ /senwill/project_1/ {
   
            root   html;
            index  index.html index.htm;
        }

        location ^~ /senwill/project_2/api {
   
            proxy_pass https://IP_2:Port_2;
            // 设置链接超时时间为3800秒
            proxy_read_timeout  3800s;
            proxy_connect_timeout 3800s;
            proxy_send_timeout 3800s;
            send_timeout 3800s;
        }

        location ^~ /senwill/project_2/ {
   
            root   html;
            index  index.html index.htm;
        }

        location ^~ /senwill/project_3/api {
   
            proxy_pass https://IP_3:Port_3;
            // 设置链接超时时间为3800秒
            proxy_read_timeout  3800s;
            proxy_connect_timeout 3800s;
            proxy_send_timeout 3800s;
            send_timeout 3800s;
        }

        location ^~ /senwill/project_3/ {
   
            root   html;
            index  index.html index.htm;
        }

        location ^~ /senwill/project_4/api {
   
            proxy_pass https://IP_4:Port_4;
            // 设置链接超时时间为3800秒
            proxy_read_timeout  3800s;
            proxy_connect_timeout 3800s;
            proxy_send_timeout 3800s;
            send_timeout 3800s;
        }

        location ^~ /senwill/project_4/ {
   
            root   html;
            index  index.html index.htm;
        }
    }
}
# 负载均衡
    upstream springboot {
   
        server 10.67.132.49:9090;
    }

    # 80端口的服务
    server {
    
        listen       80;
        server_name  10.67.132.49; # 此处应为域名

        location / {
   
            alias  html;
            index  index.html index.htm;
            try_files $uri $uri/ /senwill/index.html;
            proxy_pass http://localhost;
        }

        location ^~ /senwill/ {
   
            root   html/senwill;
            index  index.html index.htm;
            proxy_pass http://localhost;
        }

        location ^~ /sz-senwill-sky/api/ {
   
          proxy_pass http://springboot;
        }

        location ^~ /sz-senwill-sky/auth/api/ {
   
          proxy_pass http://springboot;
        }
    }
目录
相关文章
|
13天前
|
编解码 前端开发 UED
前端:移动端视口配置
移动端视口配置是指针对移动设备浏览器设置视口的宽度、高度和缩放等属性,以确保网页能根据不同的屏幕尺寸和分辨率进行适配,提供更好的用户体验。合理的视口配置是移动优先设计的关键环节。
|
19天前
|
JavaScript 前端开发 网络架构
|
15天前
|
安全 应用服务中间件 Shell
nginx配置https的ssl证书和域名
nginx配置https的ssl证书和域名
|
15天前
|
Linux 应用服务中间件 Shell
利用 ACME 实现SSL证书自动化配置更新
【10月更文挑战第11天】多项式承诺原理是密码学中的重要工具,允许证明者向验证者承诺一个多项式并证明其某些性质。Kate多项式承诺是一种知名方案,基于有限域上的多项式表示,通过生成和验证简洁的证明来确保多项式的正确性和隐私。其安全性基于离散对数假设。应用场景包括区块链中的零知识证明和可验证计算,以及多方计算和身份认证协议。在区块链中,Kate多项式承诺可用于保护隐私币和智能合约中的敏感信息。
|
15天前
|
前端开发 JavaScript 应用服务中间件
使用nginx部署网站
使用nginx部署网站
|
16天前
|
JavaScript 应用服务中间件 nginx
nginx部署vue项目
本文介绍了将Vue项目部署到Nginx的步骤,包括构建Vue项目、上传dist文件夹到服务器、安装Nginx、配置Nginx代理静态文件以及重启Nginx,确保了Vue应用可以通过域名或IP地址访问。
39 1
|
17天前
|
前端开发 JavaScript 应用服务中间件
linux安装nginx和前端部署vue项目(实际测试react项目也可以)
本文是一篇详细的教程,介绍了如何在Linux系统上安装和配置nginx,以及如何将打包好的前端项目(如Vue或React)上传和部署到服务器上,包括了常见的错误处理方法。
35 0
linux安装nginx和前端部署vue项目(实际测试react项目也可以)
|
4天前
|
JavaScript 前端开发 应用服务中间件
vue前端开发中,通过vue.config.js配置和nginx配置,实现多个入口文件的实现方法
vue前端开发中,通过vue.config.js配置和nginx配置,实现多个入口文件的实现方法
34 0
|
4天前
|
弹性计算 应用服务中间件 网络安全
ECS服务器使用:SSL证书安装、配置和问题定位指南
本文简要介绍了SSL证书的生成与部署方法,包括使用OpenSSL生成自签名证书和从CA获取证书的步骤,以及在Apache和Nginx服务器上的配置方法。此外,还提供了测试证书是否生效的方法和常见问题的解决策略,帮助确保证书正确安装并解决调试过程中可能遇到的问题。
|
8天前
|
监控 应用服务中间件 网络安全
部署Django应用:使用Gunicorn和Nginx构建高效的生产环境
部署Django应用:使用Gunicorn和Nginx构建高效的生产环境
45 0