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; }
}
}