nginx:一个端口配置两个vue项目(加前缀方法)

nginx:一个端口配置两个vue项目(加前缀方法)
在linux的配置中

server {
     #nginx监听的端口
    listen       8011;
    # 允许访问的地址
    server_name  localhost 127.0.0.1 183.213.188.77;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;
        proxy_set_header Cookie $http_cookie;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	
	# 下面的location中   /paike/api-dev-paike/   这个字段,
	#事实上,我在vue的 /config/prod.env.js 中`配置的 BASE_API: '"api-dev-paike"'
	#然而 我在下面的路由地址中,即允许浏览器访问的地址中  ,根据前缀来区分项目,这样导致的情况就是在访问api的时候,
	#浏览访问ngixn,nginx代理到后台服务器,这个过程中
	#因为访问地址中带上了前缀,/paikie ,所以请求api的时候  得在location中的 /api-dev-paike 前加上字段 /paike
	
        location /paike/api-dev-paike/ {              
               proxy_pass http://10.1.99.14:8005/;
        }
		location /base/api-dev-base/ {              
               proxy_pass http://10.1.99.13:8005/Basics/;
        }
       # 用前缀来区分不同的项目,这样导致请求api的时候也携带了这个前缀,所以在上面的api代理地址location中,给地址前面加上了字段 
	location ^~ /paike {
		alias   /etc/nginx/web/paike/;
		index  index.html index.htm;      
	}
	location /base {
		alias    /etc/nginx/web/base/ ;
		proxy_buffering off;
		index  index.html index.htm;      
	}	
    #location / {
    #   	 root   /etc/nginx/web/paike;
	#	 proxy_buffering off;
    #     index  index.html index.htm;
    #}
	
    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}
发布了33 篇原创文章 · 获赞 9 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/qq_22188085/article/details/90716816