Configuration of Nginx and Apache, Tomcat and resin static and dynamic separation

Source: Internet
Author: User

Recently, several new children's shoes have just used nginx asked me, nginx+fastcgi is not stable, occasionally 502 errors, how to solve.

I use Nginx also have more than 3 years, also think the PHP-FPM module is not stable, in the amount of traffic is not good, access to increase the number of easy to appear 502, of course, this also with nginx some of the cache settings and timeout settings related to the setting unreasonable is easy to appear. PHP-FPM dynamic generation of large pages also has no advantage, and sometimes makes the php-cgi process into a zombie process. It is said that the PHP 5.4 version has its own PHP-FPM module, the stability is improved. Tainu has not been used, no comment. In fact, I prefer nginx run static and do load reverse proxy, dynamic PHP or to the Apache processing more stable, JSP to Tomcat, resin or jboss. Nginx's ability to run static is unmatched and is the strongest in the Web server at the moment. Nginx and Apache, Tomcat, resin static and dynamic separation configuration is very simple, on a few sentence configuration, stability is also very good.


1, Nginx and Apache static and dynamic separation configuration:

Put the following configuration into the appropriate server {} of the Nginx configuration file, and if you use a different port number, change the line:
#所有php的动态页面均交由apache处理
Location ~. (PHP)? $ {
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_pass http://127.0.0.1:88;
}
#所有静态文件由nginx直接读取不经过apache
Location ~. *. (HTM|HTML|GIF|JPG|JPEG|PNG|BMP|SWF|IOC|RAR|ZIP|TXT|FLV|MID|DOC|PPT|PDF|XLS|MP3|WMA) $
{Expires 15d;}
Location ~. *. (JS|CSS)? $
{Expires 1h;}

If the fastcgi is previously set, comment out the following configuration:
# Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ php$ {
# root/var/www/html;
# Fastcgi_pass 127.0.0.1:9000;
# Fastcgi_index index.php;
# include fastcgi.conf;
#}
Restart Nginx is effective, as shown in the figure, the header display nginx,phpinfo inside display is Apache, indicating the separation of static and dynamic effect.


2, Nginx and Tomcat, resin separation of static and dynamic configuration:

Ditto, put the following configuration into the appropriate server {} of the Nginx configuration file:
#所有jsp的页面均交由tomcat或resin处理
Location ~. (JSP|JSPX|DO)? $ {
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_pass http://127.0.0.1:8080;
}
#所有静态文件由nginx直接读取不经过resin
Location ~. *. (HTM|HTML|GIF|JPG|JPEG|PNG|BMP|SWF|IOC|RAR|ZIP|TXT|FLV|MID|DOC|PPT|PDF|XLS|MP3|WMA) $
{Expires 15d;}
Location ~. *. (JS|CSS)? $
{Expires 1h;}

Reference

: http://www.server110.com/nginx/201404/8816.html

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.