nginx反向代理配置(针对vue项目打包后跨域)

本文详细介绍了Nginx服务器的配置方法,包括worker_processes、events模块的worker_connections参数设置,http模块中的sendfile、keepalive_timeout及gzip压缩等功能启用方式,并展示了两个具体的项目配置案例,涉及静态资源服务与反向代理配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#user  nobody;
worker_processes  2;

#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; 

      gzip_static on;

      gzip_buffers 16 64k;

      gzip_comp_level 5;

      gzip_types text/plain application/javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png application/octet-stream;
	# 项目1
    server {
        listen       8006;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
		add_header 'Access-Control-Allow-Origin' '*';
		add_header 'Access-Control-Allow-Credentials' 'true';
            root   html;
            index  index.html index.htm;
		    try_files $uri $uri/ /; #加上这一行
        }

location /img {
		proxy_pass http://xxx.xxx.xxx.xxx:xxxx/img;
        }

location /sys {
		proxy_pass http://xxx.xx.xxx.xxx:xxxx/sys;
        }
    }


    # 项目2
  server {
        listen       8001;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Credentials' 'true';
            root   html;
            index  index.html index.html;
	    try_files $uri $uri/ /index.html; #加上这一行
        }

	location /default/ {
			proxy_pass http://xxx.xxx.xxx.xxx:1111/;
			proxy_cookie_path / /default;
			proxy_redirect default;
			rewrite ^/default/(.*) /$1 break;
			client_max_body_size 500m;
        }
       
        location /map/ {
	   		proxy_pass http://xxxx.xxxx.xxxx.xxx:2222/;
			
			rewrite ^/map/(.*) /$1 break;
			client_max_body_size 500m;
        }

      
    }
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值