Nginx —— 用HTTP proxy module配置一个反向代理服务器
反響代理(reverse proxy)方式是指用代理服務(wù)器來接受Internet上的連接請求,然后將請求轉(zhuǎn)發(fā)給內(nèi)部網(wǎng)絡(luò)中的上游服務(wù)器,并將從上游服務(wù)器上得到的結(jié)果返回給Internet上請求連接的客戶端,此時(shí)代理服務(wù)器對外的表現(xiàn)就是一個(gè)Web服務(wù)器。充當(dāng)反響代理服務(wù)器也是nginx的一種常見的用法(反響代理服務(wù)器必須能夠大量處理并發(fā)請求)。
1》上游服務(wù)器地址 : 192.168.1.60
2》上游服務(wù)器被訪問文件:
[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》代理服務(wù)器地址: 192.168.1.210
4》 代理服務(wù)器配置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服務(wù)器(找到nginx的二進(jìn)制文件):
[root@localhost conf]# /usr/local/nginx/sbin/nginx6》客戶端測試地址: 192.168.1.93
打?yàn)g覽器地址欄輸入: http://192.168.1.210:8080/
注意: 這里一定要加conf文件中監(jiān)聽的端口,否則http默認(rèn)監(jiān)聽80端口。
頁面顯示內(nèi)容:
[root@localhost html]# cat index.html <html> <h1>This is 192.168.1.60!</h1> </html>7》測試中出現(xiàn)的問題:
<1>測試頁面出現(xiàn):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上執(zhí)行命令,開啟httpd服務(wù)
[root@localhost html]# service httpd start
?
注意:? Nginx —— nginx服務(wù)的基本配置(nginx.conf文件的詳解)
總結(jié)
以上是生活随笔為你收集整理的Nginx —— 用HTTP proxy module配置一个反向代理服务器的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Nginx —— 用HTTP核心模块配置
- 下一篇: C语言 —— 关键字(C语言标准定义的3