Nginx 配置虚拟主机域名 blog.lixiphp.com,当浏览者访问主站时,通过代理去访问 server1.blog.lixiphp.com 网站。从而达到一种负载均衡的作用。 以下是Nginx负载均衡,反向代理的配置: server { server_name blog.lixiphp.com; listen 80; location / { pr
Nginx 配置虚拟主机域名 blog.lixiphp.com,当浏览者访问主站时,通过代理去访问 server1.blog.lixiphp.com 网站。从而达到一种负载均衡的作用。
以下是Nginx负载均衡,反向代理的配置:
server { server_name blog.lixiphp.com; listen 80; location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Via "nginx"; proxy_pass http://server1.blog.lixiphp.com:80; } }
通过proxy_set_header设置 Header信息,包括Host Name(主机域名),X-Real-IP(真实IP),发送者。
PHP获取代理之前的真实信息
通过打印PHP $_SERVER即可获取到代理之前的信息。
1. 获取Host Name(主机域名)
[HTTP_HOST] => blog.lixiphp.com
如果未经proxy_set_header Host $host; 设置的话,它的值为 server1.blog.lixiphp.com。
2. 获取访问者的真实IP地址
[HTTP_X_REAL_IP] => 58.220.197.34
[HTTP_X_FORWARDED_FOR] => 58.220.197.34
如果未经proxy_set_header X-Real-IP 和 X-Forwarded-For 设置的话,它的值为 server1.blog.lixiphp.com 的IP地址,这样就非常糟糕。
(...)
Read the rest of PHP整合Nginx反向代理的用法 (42 words)
© Li Xi for LixiPHP, 2014. |
Permalink |
No comment |
Add to
del.icio.us
Post tags: Host, LNMP, Nginx, 反向代理, 负载均衡
Feed enhanced by Better Feed from Ozh

Heiße KI -Werkzeuge

Undresser.AI Undress
KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover
Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool
Ausziehbilder kostenlos

Clothoff.io
KI-Kleiderentferner

AI Hentai Generator
Erstellen Sie kostenlos Ai Hentai.

Heißer Artikel

Heiße Werkzeuge

Senden Sie Studio 13.0.1
Leistungsstarke integrierte PHP-Entwicklungsumgebung

WebStorm-Mac-Version
Nützliche JavaScript-Entwicklungstools

MantisBT
Mantis ist ein einfach zu implementierendes webbasiertes Tool zur Fehlerverfolgung, das die Fehlerverfolgung von Produkten unterstützen soll. Es erfordert PHP, MySQL und einen Webserver. Schauen Sie sich unsere Demo- und Hosting-Services an.

SublimeText3 Linux neue Version
SublimeText3 Linux neueste Version

Notepad++7.3.1
Einfach zu bedienender und kostenloser Code-Editor