国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > Nginx > 正文

nginx proxy

2024-08-30 12:22:29
字體:
來源:轉載
供稿:網友
這篇文章主要給大家介紹了關于nginx proxy_pass反向代理配置中url后加不加/的區別,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧。

前言

nginx作為web服務器一個重要的功能就是反向代理。nginx反向代理的指令不需要新增額外的模塊,默認自帶proxy_pass指令,只需要修改配置文件就可以實現反向代理。

而在日常的web網站部署中,經常會用到nginx的proxy_pass反向代理,有一個配置需要弄清楚:配置proxy_pass時,當在后面的url加上了/,相當于是絕對根路徑,則nginx不會把location中匹配的路徑部分代理走;如果沒有/,則會把匹配的路徑部分也給代理走(這樣配置可以參考這篇文章)。

下面舉個小實例說明下:

centos7系統庫中默認是沒有nginx的rpm包的,所以我們自己需要先更新下rpm依賴庫

1)使用yum安裝nginx需要包括Nginx的庫,安裝Nginx的庫

[root@localhost ~]# rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

2)使用下面命令安裝nginx

[root@localhost ~]# yum install nginx

3)nginx配置

[root@localhost ~]# cd /etc/nginx/conf.d/[root@localhost conf.d]# cat test.confserver {listen 80;server_name localhost;location / {root /var/www/html;index index.html;}} [root@localhost conf.d]# cat /var/www/html/index.htmlthis is page of test!!!!

4)啟動Nginx

[root@localhost ~]# service nginx start //或者使用 systemctl start nginx.service

5)測試訪問(103.110.186.23是192.168.1.23機器的外網ip)

[root@localhost conf.d]# curl http://192.168.1.23this is page of test!!!!

看看下面幾種情況:分別用http://192.168.1.23/proxy/index.html進行訪問測試

為了方便測試,先在另一臺機器192.168.1.5上部署一個8090端口的nginx,配置如下:

[root@bastion-IDC ~]# cat /usr/local/nginx/conf/vhosts/haha.confserver {listen 8090;server_name localhost;location / {root /var/www/html;index index.html;}}[root@bastion-IDC ~]# cat /var/www/html/index.htmlthis is 192.168.1.5[root@bastion-IDC ~]# /usr/local/nginx/sbin/nginx -s reload

測試訪問(103.110.186.5是192.168.1.5的外網ip):

[root@bastion-IDC ~]# curl http://192.168.1.5:8090this is 192.168.1.5


192.168.1.23作為nginx反向代理機器,nginx配置如下:

1)第一種情況:

[root@localhost conf.d]# cat test.confserver {listen 80;server_name localhost;location / {root /var/www/html;index index.html;} location /proxy/ { proxy_pass http://192.168.1.5:8090/;}}

這樣,訪問http://192.168.1.23/proxy/就會被代理到http://192.168.1.5:8090/。p匹配的proxy目錄不需要存在根目錄/var/www/html里面

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 康保县| 玉山县| 合水县| 石阡县| 丽江市| 汉源县| 堆龙德庆县| 大新县| 荥阳市| 车险| 遂宁市| 木里| 克东县| 沅陵县| 巴青县| 民勤县| 凉城县| 融水| 宜君县| 西华县| 宁安市| 潮州市| 新津县| 博客| 曲靖市| 行唐县| 安远县| 托克逊县| 河池市| 文山县| 天峨县| 靖西县| 盐边县| 汉寿县| 渑池县| 泽州县| 辉县市| 高青县| 兴安盟| 白城市| 神农架林区|