反向代理
1,先下载ngix,下载了个1.8.1版本的 :http://nginx.org/en/download.html 解压
(内网安装参考https://www.cnblogs.com/taiyonghai/p/6728707.html)
2,安装相关组件,先进入ngix目录
3,安装相关组件,先进入ngix目录
-
#安装gcc-c++,autoconf表示自动配置,automake表示自动编译
-
yum install -y gcc gcc-c++ autoconf automake
-
#安装pcre
-
yum -y install pcre pcre-devel
-
#安装zlib
-
yum -y install zlib zlib-devel
-
安装openssl
-
yum install -y openssl openssl-devel
4,安装ngix
./configure
5,编译
make && make install
6,启动运行ngix
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
或者 ,两者取一项输入即可
/usr/local/nginx/sbin/nginx
# -c后面的可以忽略不输入,这样的话,就是加载默认的配置文件nginx.conf
配置反向代理
新建配置文件 tomcatNginx.conf
内容为:
user nobody;
worker_processes 4;
events{
worker_connections 1024;
}
http{
upstream xd-project{
server 123.1.2.1;
server .13.231.3;
}
server{
listen 80;
location / {
proxy_pass http://xd-project;
}
}
运行负载均衡ba版的nginx
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/tomcatNginx.conf
访问80端口
相关配置文件截图,以及解决vue项目刷新404页面问题
重启
、/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/tomcatNginx.conf -s reload
-c 表示要加载的配置,没有就是默认配置
rewrite 实现URL跳转
rewrite 是 nginx的静态重写模块
基本用法是 rewrite patten replace flag
patten是正则表达式,与patten匹配的URL会被改写为replace,flag可选
例如将旧域名跳转到新域名上
server {
listen 80;
server_name www.old.com;
rewrite ".*" http://www.new.com;
}
跳转到新域名上时保留路径
server
{
listen 80;
server_name www.old.com;
rewrite "^/(.*)$" http://www.new.com/$1;
}
rewrite与location配合实现图片文件跳转到cdn
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
expires 30d;
rewrite "^/uploadfile\/(.*)$" http://static.XXX.com/uploadfile/$1;
}