[root@host1 conf.d]# pwd/usr/local/nginx/conf.d
②配置[root@host1 conf.d]# vim test1.conf
这里设置监听端口为8080
server { resolver 114.114.114.114; listen 8080; location / { proxy_pass http://$http_host$request_uri; }}
③重启nginx 二、反向代理(host1 host2 localhost 分别为三台linux虚拟机) #简单模拟host2 和 localhost 安装httpd
①localhost配置localhost 设置为仅主机模式添加ip 192.168.91.131
[root@localhost ~]# echo "this is a test" > /var/www/html/index.html[root@localhost ~]# systemctl start httpd[root@localhost ~]# systemctl stop firewalld[root@localhost ~]# setenforce 0
②host1 配置这里设置监听端口为8800
[root@host1 conf.d]# vim test2.conf
server { listen 8800; server_name localhost; location /{ proxy_pass http://192.168.91.131; }}
如下:测试语法无误
重启nginx
③使用一台不能ping通linux电脑curl此台电脑需要关掉防火墙并设置selinux
curl 8800 端口
1、配置用于测试的两台Web服务器(host2、host3)host2、host3为两台web服务器
均安装epel(rhel7)
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
使用yum下载nginx
yum install nginx -y
mkdir /usr/share/nginx/html/{www,bbs}/logs -pcd /etc/nginx/conf.d
vim vhost.conf
server { listen 80; server_name bbs.yunjisuan.com; location / { root /usr/share/nginx/html/bbs; index index.html index.htm; } access_log /usr/share/nginx/html/bbs/logs/access_bbs.log main;}server { listen 80; server_name www.yunjisuan.com; location / { root /usr/share/nginx/html/www; index index.html index.htm; } access_log /usr/share/nginx/html/www/logs/access_www.log main;}
echo "`hostname -I `www" > /usr/share/nginx/html/www/index.htmlecho "`hostname -I `www" > /usr/share/nginx/html/bbs/index.html
2、host1、host2关掉防火墙,设置selinuxsystemctl stop firewalldsetenforce 0
3、host1、host2开启nginxsystemctl start nginx检查语法nginx -t
4、重新找一台电脑curl