nginx 反向代理

1.下载nginx依赖包

1 yum install -y gcc pcre pcre-devel zlib zlib-devel gcc-c++ autoconf automake

2.解压安装包

9  tar -zxvf nginx-1.19.2.tar.gz 

3.指向configure 执行make

11 cd nginx-1.19.2
12 ./configure --prefix=/usr/local/nginx
13 make && make install

4.启动nginx

23 whereis nginx
24 cd /usr/local/nginx/
26 cd sbin/
27 sudo ./nginx
29 yum install -y net-tools
31 ps aux | grep nginx 查看nginx进程

5.反向代理

1.修改nginx文件
vi /usr/local/nginx/conf/nginx.conf

    server {
    listen       80; (端口号)
    server_name  www.testdomain.com ; (自己的域名)
    #charset koi8-r;
    #access_log  logs/host.access.log  main;

    location / {
        root   html;
        index  index.html index.htm;
        
         proxy_set_header X-Real-IP $remote_addr;                 (设置反向代理)
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         
         proxy_pass    http://www.baidu.com; (目的域名)

}
2.重启nginx服务,设置本机地址映射
[root@localhost nginx]# /usr/local/nginx/sbin/nginx -s reload

编辑windows中C:\Windows\System32\drivers\etc下的hosts文件
添加 虚拟机IP 域名

最后结果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值