nginx代理前端VUE项目

user root;
worker_processes auto;
pid /run/nginx.pid;
events {
        worker_connections 768;
}
http {
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        include /etc/nginx/conf/mime.types;
        default_type application/octet-stream;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;
        access_log /etc/nginx/logs/access.log;
        error_log /etc/nginx/logs/error.log;
        gzip on;
        gzip_disable "msie6";
        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
       server {
          listen 8080;   //前端端口
           listen 443 ssl;
           server_name 192.168.140.80;	# 前端地址
           # ssl on;
           ssl_certificate /etc/nginx/1data.crt;
           ssl_certificate_key /etc/nginx/1data.key;
          location / {
             root /root/dist;     //前端代码放的路径,将打包生成的dist文件夹放到/root/下
             index index.html;
          }
}
        

        //将后台的http代理成https(如果不需要代理成https下面的信息可以不要)
         upstream xservice_proxy {
           server 192.168.140.80:1234;	# 需要代理的后台http地址端口
         }
		 
		 
		 server {
           listen 1235  backlog=65535;   # ´úÀíºó¶Ë¿Ú
		   error_page 497 https://$host:1235$request_uri; # ´代理成https后的端口
           server_name 192.168.140.80;	# 代理后的地址å
           ssl on;
           ssl_certificate /etc/nginx/1data.crt;
           ssl_certificate_key /etc/nginx/1data.key;
          location / {
               proxy_pass http://xservice_proxy;
               proxy_set_header  Host  $host:1234; # ±¾À´¶Ë¿Ú
               proxy_set_header  X-Real-IP  $remote_addr;   
               proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
               proxy_set_header Accept-Encoding gzip;
     }
   }

}

 

你可能感兴趣的:(nginx)