Nginx is a good tool for processing static content. although Apache occupies more memory and has a poor performance, it has been relatively stable. However, Nginx FastCGI may sometimes encounter a 502BadGateway error. An optional method is to use Nginx as a front-end proxy to process static content and forward dynamic requests to backend Apache. NginxServer is configured as follows (test environment): server
Nginx is a good tool for processing static content. although Apache occupies more memory and has a poor performance, it has been relatively stable. However, Nginx FastCGI may sometimes encounter a 502 Bad Gateway error. An optional method is to use Nginx as a front-end proxy to process static content and forward dynamic requests to backend Apache. The Nginx Server configuration is as follows (test environment ):
Server {listen 80; server_name test.com; location/{root/www/test; index. php index.html; # When the Nginx file cannot be found, forward the request to the backend Apache error_page 404 @ proxy; # css, js static file to set the validity period of 1 day location ~ . * \. (Js | css) $ {access_log off; expires 1d ;}# the image setting is valid for 3 days location ~ . * \. (Gif | jpg | jpeg | png | bmp | swf) $ {access_log off; expires 3d ;}# the dynamic file. php request is forwarded to the backend Apache location ~ \. Php $ {# proxy_redirect off; # proxy_pass_header Set-Cookie; # sending Cookie $ http_cookie; # passing the Real IP address to the backend proxy_set_header Host $ http_host; proxy_set_header X-Real-IP $ remote_addr; proxy_set_header X-Forwarded-For $ scheme; proxy_pass http: // 127.0.0.1: 8080;} location @ proxy {proxy_set_header Host $ http_host; proxy_set_header X-Real-IP $ remote_addr; proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for; proxy_pass http: // 127.0.0.1: 8080 ;}}
Environment: CentOS6.0-64bit, Nginx 1.0.8, Apache 2.2.21, PHP 5.3.8. Nginx comprehensively takes over port 80, Apache is back to the second line, and listening to port 8080.