使用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;
        }
    }
目录
相关文章
|
2天前
|
存储 缓存 监控
|
2天前
|
安全 应用服务中间件 Shell
nginx配置https的ssl证书和域名
nginx配置https的ssl证书和域名
|
2天前
|
存储 缓存 前端开发
理清 nginx 中的 location 配置
理清 nginx 中的 location 配置
|
2天前
|
负载均衡 算法 应用服务中间件
Nginx安装及配置详解
Nginx安装及配置详解
|
2天前
|
前端开发 JavaScript 应用服务中间件
使用nginx部署网站
使用nginx部署网站
|
2天前
|
缓存 负载均衡 算法
Nginx配置详解
Nginx配置详解
|
2天前
|
负载均衡 Java 应用服务中间件
Nginx负载均衡配置
Nginx负载均衡配置
|
1天前
|
应用服务中间件 Linux Shell
Linux 配置 Nginx 服务的详细步骤,绝对干货
Linux 配置 Nginx 服务的详细步骤,绝对干货
8 0
|
2天前
|
缓存 安全 应用服务中间件
nginx配置proxy_set_header
nginx配置proxy_set_header
|
2天前
|
负载均衡 算法 应用服务中间件
【nginx】配置Nginx实现负载均衡
【nginx】配置Nginx实现负载均衡