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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_42167759/article/details/85111924

反响代理(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文件的详解)

猜你喜欢

转载自blog.csdn.net/weixin_42167759/article/details/85111924