nginx 配置https 前端vue多项目,后端springboot反向代理共用80端口


user  root;   #用户名和nginx启动用户保持一致,防止403
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;

    sendfile        on;
    #tcp_nopush     on;
    keepalive_timeout  65;
    #gzip  on;
    #此处主要配置nginx ssl证书
    server {
        #SSL 访问端口号为 443
        listen 443 ssl; 
        #填写绑定证书的域名
        server_name app.xxx.com.cn; 
        #证书文件名称
        ssl_certificate xxx.com.cn_bundle.crt; 
        #私钥文件名称
        ssl_certificate_key xxx.com.cn.key; 
        ssl_session_timeout 5m;
        #请按照以下协议配置
        ssl_protocols TLSv1.2 TLSv1.3; 
        #请按照以下套件配置,配置加密套件,写法遵循 openssl 标准。
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; 
        ssl_prefer_server_ciphers on;
        #对应下面app的反向代理
        #前端项目1
        location /app1/ {
            proxy_pass http://127.0.0.1:8066/;            
        }
		#前端项目2
        location /app2/ {
            proxy_pass http://127.0.0.1:8067/; 
        }
		#后端springboot项目jar启动,可以使用nginx反向代理80端口访问后端接口,访问记得加上接口名称
        location / {
        proxy_pass **https**://localhost:9001;#此处是你后端springboot有没有配置https
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    	}

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

    server {
        listen 8066;
        location / {
            root /usr/local/nginx/html/app1;
            index  index.html index.htm;
            autoindex off;       #开启nginx目录浏览功能
            autoindex_exact_size off;   #文件大小从KB开始显示
            charset utf-8;          #显示中文
            #add_header 'Access-Control-Allow-Origin' '*'; #允许来自所有的访问地址
            #add_header 'Access-Control-Allow-Credentials' 'true';
            add_header 'Access-Control-Allow-Methods' 'GET, PUT, POST, DELETE, OPTIONS'; #支持请求方式
            add_header 'Access-Control-Allow-Headers' 'Content-Type,*';

       }
    }
    

    server {
        listen 8067;
        location / {
            root /usr/local/nginx/html/app2;
            index  index.html index.htm;
            autoindex off;       #开启nginx目录浏览功能
            autoindex_exact_size off;   #文件大小从KB开始显示
            charset utf-8;          #显示中文
            #add_header 'Access-Control-Allow-Origin' '*'; #允许来自所有的访问地址
            #add_header 'Access-Control-Allow-Credentials' 'true';
            add_header 'Access-Control-Allow-Methods' 'GET, PUT, POST, DELETE, OPTIONS'; #支持请求方式
            add_header 'Access-Control-Allow-Headers' 'Content-Type,*';

        }
    }

}

你可能感兴趣的:(springboot,java,nginx,ssl,vue,springboot)