环境说明
Centos 7版本
主机名 | IP地址 |
nginx | 192.168.10.150 |
nginx-2 | 192.168.10.151 |
nginx-3 | 192.168.10.152 |
1、Nginx上配置了动静分离,css,js文件在Nginx上,后端是Nginx-2,如需要动静分离配置请访问动静分离配置,访问Nginx的服务器结果如下:
![](https://i-blog.csdnimg.cn/blog_migrate/e707d0e7b24dd77129ef53a943a39ff1.png)
2、在Nginx-3的配置文件做个代理,把请求转发到Nginx192.168.10.150上去,修改配置文件nginx.conf的location,如下:
location / {
proxy_pass http://192.168.10.150;
#root html;
#index index.html index.htm;
}
访问结果如下:
![](https://i-blog.csdnimg.cn/blog_migrate/50f9948eeb3e4e390687b3ad5ca2505c.png)
配置
[root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://192.168.10.151;
}
location /css {
#valid_referers指定可访问的名单,none代表没有头域不存在,blocked代表请求含有referer,但被防火墙或代理服务器去掉了http或https,域名
valid_referers none blocked 192.168.10.150;
#如果不是可访问的名单,返回403
if ($invalid_referer) {
return 403;
}
root html;
index index.html index.htm;
}
location /js {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
[root@nginx ~]# systemctl restart nginx
验证
![](https://i-blog.csdnimg.cn/blog_migrate/63723e19ac1923dc08a667ff9d1de58b.png)
完成!