配置nginx反向代理
1、配置nginx反向代理,实现api.x.com域名代理本地9001端口
1.1 安装nginx
1.1.1 安装依赖包
[ nginx]# yum install gcc pcre-devel openssl-devel zlib-devel -y
1.1.2 创建nginx用户
[ ~]# useradd -r -s /sbin/nologin nginx
1.1.3 官网下载nginx源码包,并解压,编译安装
[ src]# pwd /usr/local/src [ src]# ls nginx-1.16.1.tar.gz [ src]# tar xf nginx-1.16.1.tar.gz [ src]# ls nginx-1.16.1 nginx-1.16.1.tar.gz [ src]# mv nginx-1.16.1 nginx [ src]# cd nginx/ [ nginx]# ls auto CHANGES.ru configure html man src CHANGES conf contrib LICENSE README [ nginx]# ./configure --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_dav_module --with-http_stub_status_module --with-threads --with-file-aio [ nginx]# make -j 4 && make install
1.1.4 配置环境变量,方便启动nginx
[ sbin]# export PATH="/usr/local/nginx/sbin:$PATH"
1.1.5 修改nginx配置文件
[ nginx]# vim /usr/local/nginx/conf/nginx.conf ###在配置文件增加如下一行 include /usr/local/nginx/conf.d/*.conf; [ conf.d]# pwd /usr/local/nginx/conf.d [ conf.d]# cat proxy.conf server { server_name api.x.com; location / { proxy_pass http://localhost:9001; } } server { listen 9001; server_name _; root /data/nginx; index index.html; }
1.1.6 准备测试网页
[ ~]# mkdir /data/nginx/ [ ~]# echo proxypass > /data/nginx/index.html
1.3 测试
1.3.1 修改/etc/hosts文件
[ ~]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 10.1.1.242 c1 api.x.com
1.3.2 在c2服务器上测试
[ conf.d]# curl api.x.com proxypass [ conf.d]# curl api.x.com proxypass [ conf.d]# curl api.x.com proxypass [ conf.d]# curl api.x.com proxypass [ conf.d]# curl api.x.com proxypass [ conf.d]# curl api.x.com proxypass
相关推荐
scaleqiao 2020-10-22
SZStudy 2020-07-04
ssihc0 2020-06-14
某些公司会墙特定网站,如果你有一个可访问的域名和服务器,就可以通过nginx反向代理来来解决这些问题。比如现在我们用mirror.example.com镜像www.baidu.com,以下是详细操作。
byourb 2020-06-05
岁月如歌 2020-04-15
carolAnn 2020-04-14
Strongding 2020-04-08
ysmh00 2020-03-27
APCDE 2020-02-21
Freshairx 2020-02-19
tinydu 2020-02-12
carolAnn 2020-02-01
liwf 2020-01-13
nginxs 2020-01-05
Caleb0 2019-12-27
Strongding 2019-12-24
byourb 2019-12-18