search
Homephp教程php手册PHP整合Nginx反向代理的用法

PHP整合Nginx反向代理的用法

Jun 06, 2016 pm 08:13 PM
nginxphpactingreverseIntegrateusageConfiguration

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负载均衡反向代理+PHP实现

以下是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

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools