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;




    # 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  video.lidongeco.com;#域名
		ssl                  on;
		ssl_certificate      D:/nginx-1.17.9/nginx-1.17.9/nginx-1.17.9/ssl/3593946_video.lidongeco.com.pem;#证书路径
		ssl_certificate_key   D:/nginx-1.17.9/nginx-1.17.9/nginx-1.17.9/ssl/3593946_video.lidongeco.com.key;#证书路径
		ssl_session_timeout  5m;
		ssl_protocols TLSv1 TLSv1.1 TLSv1.2 ;
		ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
		ssl_prefer_server_ciphers   on;
		
		location / {
             #前端项目端口号
            proxy_pass https://127.0.0.1:8082;
            
			}
		#微信小程序配置JGKvvjQIb3.txt文件是小程序中下载下来的,放置路径如下
		location /JGKvvjQIb3.txt {
			alias D:/nginx-1.17.9/nginx-1.17.9/nginx-1.17.9/JGKvvjQIb3.txt;
		}
		 location /websocket/ {
			# websocket路径下的请求转发给真正的后端服务器
			proxy_pass https://192.168.xxx.xx:8096;
			proxy_set_header Host $host:$server_port;
			proxy_set_header Remote_Addr $remote_addr;
			proxy_set_header X-Real-IP $remote_addr;
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			proxy_http_version 1.1;
			proxy_set_header Upgrade $http_upgrade;
			proxy_set_header Connection "upgrade";
		}	
		location /api/ {
			#  项目中/api 路径下的访问都是访问后端接口,请求转发给真正的后端服务器
			proxy_pass https://192.168.xxx.xx:8096;
			
		}
		location /static/ {
			# 静态资源请求转发给真正的后端服务器
			proxy_pass https://192.168.xxx.xxx:8096;
			
		}			
		
	}
	  #  修改部分====================================================	

}

你可能感兴趣的:(Nginx代理前后端分离项目配置)