Nginx —— 用HTTP proxy module配置一个反向代理服务器

反响代理(reverse proxy)方式是指用代理服务器来接受Internet上的连接请求,然后将请求转发给内部网络中的上游服务器,并将从上游服务器上得到的结果返回给Internet上请求连接的客户端,此时代理服务器对外的表现就是一个Web服务器。充当反响代理服务器也是nginx的一种常见的用法(反响代理服务器必须能够大量处理并发请求)。

1》上游服务器地址 : 192.168.1.60

2》上游服务器被访问文件:

[root@localhost html]# ip addr | grep 192
    inet 192.168.1.60/24 brd 192.168.1.255 scope global noprefixroute eno1
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
    inet 192.168.135.1/24 brd 192.168.135.255 scope global vmnet8
[root@localhost html]# 
[root@localhost html]# pwd
/var/www/html
[root@localhost html]# cat index.html 
<html>
<h1>This is 192.168.1.60!</h1>
</html>

3》代理服务器地址: 192.168.1.210

4》 代理服务器配置conf:

[root@localhost conf]# cat nginx.conf | grep -v "#"
worker_processes  1;

events {
	worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    server {
	listen       8080;

	 server_name  localhost;

	location / {
		proxy_pass http://192.168.1.60;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

5》启动nginx服务器(找到nginx的二进制文件):

[root@localhost conf]# /usr/local/nginx/sbin/nginx

6》客户端测试地址: 192.168.1.93

打浏览器地址栏输入: http://192.168.1.210:8080/

注意: 这里一定要加conf文件中监听的端口,否则http默认监听80端口。

页面显示内容:

[root@localhost html]# cat index.html 
<html>
<h1>This is 192.168.1.60!</h1>
</html>

7》测试中出现的问题:

<1>测试页面出现:An error occurred.

An error occurred.

Sorry, the page you are looking for is currently unavailable.
Please try again later.

If you are the system administrator of this resource then you should check the error log for details.

Faithfully yours, nginx.

解决方式:在1.60上执行命令,开启httpd服务

[root@localhost html]# service httpd start

 

注意:  Nginx —— nginx服务的基本配置(nginx.conf文件的详解)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值