欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 运维知识 > Nginx >内容正文

Nginx

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

发布时间:2025/10/17 Nginx 54 豆豆
生活随笔 收集整理的这篇文章主要介绍了 Nginx —— 用HTTP proxy module配置一个反向代理服务器 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

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

1》上游服务器地址 : 192.168.1.60

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

[root@localhost html]# ip addr | grep 192inet 192.168.1.60/24 brd 192.168.1.255 scope global noprefixroute eno1inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0inet 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文件的详解)

总结

以上是生活随笔为你收集整理的Nginx —— 用HTTP proxy module配置一个反向代理服务器的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。