Nginx
一、浏览器配置
if ($http_user_agent ~* "MSIE") #MSIE IE浏览器
{proxy_pass http://dynamic_pools;}
if ($http_user_agent ~* "Firefox") #Firefox火狐浏览器
{proxy_pass http://static_pools;}
二、端口配置
三、虚拟主机配置
Nginx 的虚拟主机是通过HTTP请求中的Host值来找到对应的虚拟主机配置,如果找不到呢?那 Nginx 就会将请求送到含有的 default_server 的 server来处理,如果没有指定为 default_server 的话,就以第一个server配置文件为准。(另外,内部业务服务节点,访问另外一个内部集群服务的话,如果需要配置nginx外网域名的话,可以在业务服务节点配置 修改/etc/HOSTS文件, nginx外网域名与内网IP进行解析,免得走外网;)
参照:https://blog.youkuaiyun.com/daiyudong2020/article/details/73863437
1、基于端口;
2、基于域名; 通过修改本地hosts文件来验证
192.168.1.150 www.sina.com
192.168.1.150 sports.sina.com.cn
对应nginx配置
server {
listen 80;
server_name www.sina.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index sina.html;
}
}
server {
listen 80;
server_name sports.sina.com.cn;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index sports.html;
}
}
访问www.sina.com,会走sina.html;
访问sports.sina.com.cn,会走sports.html;
访问192.168.1.150,会走第一个server sina.html;
3、静态资源配置
http://**** /staticresource/Desktop.html
4、路由器上增加域名和服务器,hosts文件的配置;解决局域网中所有客户端请求内网服务器,域名不走外网的问题;
5、server_name 存在的意义: 用于映射到多个二级域名使用; 一个大型网站,存在一级域名,和2级域名 eg suning.com pindao.suning.com,reg.suning.com 二级域名又对应不同的服务; 当一个请求reg.suning.com/**过来后,域名服务商会把suning.com的转发到nginx服务器,端口号都是80,然后匹配server_name,决定走哪台虚拟server;
6、proxy_pass 如果出现URI部分,那边 请求URL中对应location后的路径就会覆盖掉,前提 location的路径不是正则表达式;如果没有URI,保留location后的路径;
7、配合frps的实际场景:
http://*****.***.com/ 这个域名会解析到106.15.61.55这个IP,然后根据端口80转发到nginx,nginx又转发到http://106.15.61.55:8086,然后根据端口frps 8086转发到南京的开发环境200 frpc配置
remote_port=8086的配置项,
即南京开发环境80;然后走到80的nginx 服务器,又根据 域名 *****.***.com进行分发;
8、location误区参照 https://www.cnblogs.com/jingxiaoniu/p/7007653.html
如何添加第三方模块
1. 原来所安装的配置,你必在重新安装新模块的时候,加上
2. 不能直接make install
安装方法 configure --prefix=/data/program/nginx ./configure --prefix=/安装目录 --add-module = /第三方模块的目录
./configure --prefix=/data/program/nginx --with-http_stub_status_module --with-http_random_index_module
make;
cp objs/nginx $nginx_home/sbin/nginx
四、防火墙的问题
nginx connect() failed (113: No route to host
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动