Nginx的Https配置及代理api接口配置

本文详细介绍了如何使用Nginx配置HTTPS,包括获取SSL证书、编辑Nginx配置文件以实现HTTPS服务,并配置代理以转发到Java接口。通过设置代理连接超时、读取超时等参数,确保了后端接口的稳定访问。
摘要由CSDN通过智能技术生成

文章介绍nginx如何配置https并配置代理java接口

1、获取证书

使用certbot生成证书:如何生成证书?

(1)将cert.pem复制到该工具进行解析 进入工具网站转换pem
(2)解析完成后下载解析后的文件
(3)将下载的文件内容全部复制到fullchain.pem文件的中间部分
2、nginx的配置文件
#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/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;

    server {
        listen       80;
        
        # gzip config 前端加载慢问题这样解决
        gzip on;
        gzip_min_length 1k;
        gzip_comp_level 9;
        gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
        gzip_vary on;
        gzip_disable "MSIE [1-6]\.";
        
        server_name  localhost;  # 这里配置域名
        location / {
            root   "D:\snowy\dist";
			try_files $uri $uri/ @router;
            index  index.html index.htm;
			error_page 405 =200 http://$host$request_uri;
        }
		#代理后端接口
		location /api/ {
			proxy_pass http://localhost:9003/api/;   #转发请求的地址
			proxy_connect_timeout 6000;     #链接超时设置
			proxy_read_timeout 6000;        #访问接口超时设置
		}
		location @router {
            rewrite ^.*$ /index.html last;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}


    # 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;
         gzip on;
        gzip_min_length 1k;
        gzip_comp_level 9;
        gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
        gzip_vary on;
        gzip_disable "MSIE [1-6]\.";
        server_name  *****.com;   #自己的域名
        ssl_certificate      D:\\nginx-1.21.6\\zzjx.js-whzl.com\\fullchain.pem;
        ssl_certificate_key  D:\\nginx-1.21.6\\zzjx.js-whzl.com\\privkey.key;
		ssl_trusted_certificate D:\\nginx-1.21.6\\zzjx.js-whzl.com\\fullchain.pem;
	
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers ALL:!DH:!EXPORT:!RC4:+HIGH:+MEDIUM:!LOW:!aNULL:!eNULL;
        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

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

        location / {
            root   "D:\snowy\dist_test\dist";
			try_files $uri $uri/ @router;
            index  index.html index.htm;
        }
		#代理后端接口
		location /api/ {
			proxy_pass http://localhost:9003/api/;   #转发请求的地址
			proxy_connect_timeout 6000;     #链接超时设置
			proxy_read_timeout 6000;        #访问接口超时设置
		}
    }

}

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我是福强

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值