一、实现功能
在centos系统中布署nginx反向代理,通过客户端域名解析到对应的网页。
二、步骤
1.添加自定义配置文件所在的配置文件夹revhost,即所有反向代理配置都在这个文件内,且以".conf"后缀结尾
cd /usr/local/nginx/conf/
mkdir revhost
2.配置nginx.conf,使包含/usr/local/nginx/conf/revhost中所有 “.conf”结尾的文件。
添加:include revhost/*.conf;
# location / {
# root html;
# index index.html index.htm;
# }
#}
include revhost/*.conf;
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
3.添加反向代理配置文件hadoop01-nginx.conf
[root@hadoop01 revhost]# pwd
/usr/local/nginx/conf/revhost
[root@hadoop01 revhost]# vi hadoop01-nginx.conf
server {
listen 80;
autoindex on;
server_name hadoop01;
access_log /usr/local/nginx/logs/hadoop01.access.log combined;
index index.html index.htm index.jsp index.php;
#error_page 404 /404.html;
if ( $query_string ~* ".*[\;'\<\>].*" ){
return 404;
}
location / {
proxy_pass http://192.168.130.3:50070;
add_header Access-Control-Allow-Origin *;
}
}
备注:实现功能即,通过hadoop01访问服务器80端口的,即跳转到hadoop首页
http://192.168.130.3:50070;
4.修改windows本地C:\Windows\System32\drivers\etc\hosts,添加
192.168.130.3 hadoop01
5.重启(切记,一定重启否则不生效)
[root@hadoop01 nginx]# pwd
/usr/local/nginx
[root@hadoop01 nginx]# ./sbin/nginx -s reload
6.在本地访问http://hadoop01