apache2.2 反向代理 配置css js静态文件

html-css057

apache2.2 反向代理 配置css js静态文件,第1张

1.先去掉下面两行的注释

LoadModule proxy_module

modules/mod_proxy.so

LoadModule proxy_http_module

modules/mod_proxy_http.so

2.然后在最后增加

ProxyPass /images !

ProxyPass /css !

ProxyPass /js !

ProxyPass / http://localhost:8080/这个也可以写为:

ProxyPass

/oa

http://localhost:8080/oa

ProxyPassReverse

/oa

http://localhost:8080/oa

也可以连续增加以上两行,就是多个tomcat启动

ProxyPass /meb http://192.168.6.103:8081/meb

ProxyPassReverse /meb http://192.168.6.103:8081/meb

对于新版本的vue,需要新增vue.config.js,并添加如下配置,产生的效果是一样的

其实用 相对路径 来解决这个问题不是最好的方案,甚至 vue-cli4.x 之后,就不支持将 publicPath 设置为 ./ 了。

看了 公司的项目 及 Nuxt框架 的推荐,均是推荐使用绝对路径来设置 publicPath

这里主要是使用nginx 实现对多个tomcat的代理配置. 首先nginx 的配置文件为conf/ngins.conf

描述场景 有8080端口下Tomcat1下项目A.

有8090端口下tomcat2下项目B.

......

通过使用一个域名+(不同)项目名 访问不同的tomcat下的项目.

配置文件如下:(均在conf文件内添加即可 不删除或修改其他内容).

server {

listen 80

server_name localhost

#charset koi8-r

#access_log logs/host.access.log main

location /Name1 {

#root html

proxy_pass http://localhost:8080/A

proxy_redirect http://host:8080 http://$host:$server_port//这个配置是将我们的host主机名和端口号,被host:8080所替代.不然因为域名问题,加载js,css文件会报404错误.

index index.html index.htm

}

location /Name2 {

#root html

proxy_pass http://localhost:8090/B

proxy_redirect http://host:8090 http://$host:$server_port

index index.html index.htm

}

..........省略

}

配置保存,重启.吐槽一下nginx的重启运行.很麻烦.我是在任务管理器内直接停止后重启的.

以上即可实现 localhost+A-------访问tomcat A项目

localhost+B-------访问tomcat B项目