Nginx + Apache configure reverse proxy and static resource cache

Source: Internet
Author: User
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.

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.