Implement reverse Proxy in Nginx

Source: Internet
Author: User
Tags log php server

2 Uses of Nginx

Web server for static content;

Reverse proxy server;

The characteristics of Nginx as reverse proxy

The receiving user request is asynchronous, that is, the user requests are all received, and then the back-end Web server is sent once, which greatly reduces the pressure of the back-end Web server;

No long connection between the Nginx agent and the back-end Web server;

When sending a response message, the side receives data from the backend Web server and sends it to the client;

The modules involved

Proxy: Standard HTTP module, implement reverse proxy function

Upstream: Standard HTTP module, load balancing function for back-end Web server scheduling;

FastCGI: Standard HTTP module, the PHP dynamic request agent to the back-end PHP server;

Configuring deployment

description : In this article, Nginx is responsible for static access processing, dynamic access will be proxy to the back-end PHP server;

# vi/etc/nginx/nginx.html Worker_processes 2;
Pid/var/run/nginx.pid;
    Events {worker_connections 1024;} http {include mime.types;
    Default_type Application/octet-stream; Log_format Main ' $remote _addr-$remote _user [$time _local] "$request" "$status $body _bytes_sent
    "$http _referer" "$http _user_agent" "$http _x_forwarded_for";
    Sendfile on;
    Keepalive_timeout 65;
    Upstream backend {server 172.16.25.112:9000;
        } server {Listen 80;
        server_name xxrenzhe.lnmmp.com;
        Access_log/var/log/nginx/lnmmp.access.log;
        Error_log/var/log/nginx/lnmmp.errors.log notice;
        root/www/lnmmp.com;
            Location/{try_files $uri @missing; # access the local static resource first, if it fails, go to the missing processing block;} location @missing { Rewrite ^ (. *[^/]) $ $1/permanent; # when accessing a domain name or IP address directly, add a trailing end to it and return to the rewrite ^/index.phpLast # will always inaccessible resources (such as 404 errors), all redirected to the home page} # prohibits system directory access, but allows the specified type of static file access to location ~* ^/system/.+\.
            (Jpg|jpeg|png|gif|css|js|swf|flv|ico) $ {expires Max;
            Tcp_nodelay off;
        Tcp_nopush on;
        # When accessing/system/, you can jump back directly to the page location ~/system/{rewrite ^/index.php last;
            } location ~* \.php$ {Default_type text/html;
            CharSet Utf-8;
            Fastcgi_pass backend;
            Fastcgi_index index.php;
            Fastcgi_param script_filename $document _root$fastcgi_script_name;
        Include Fastcgi_params; }
    }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.