How to install and configure Nginx and PHP-fpm

How to install and configure Nginx and PHP-fpm

nginx itself cannot handle PHP, it is just a web server, when a request is received, if it is a PHP request, it will be sent to the PHP interpreter for processing, and the result will be returned to the client. Nginx generally sends the request to the fastcgi management process for processing, and the fascgi management process selects the cgi sub-process processing result and returns it to be processed by nginx This article takes php-fpm as an example to introduce how to make nginx support PHP 1. Compile and install php-fpm What is PHP-FPM PHP-FPM is a PHP FastCGI manager for PHP only, available at http://php-fpm.org/download to download. PHP-FPM is actually a patch of the PHP source code, aiming to integrate FastCGI process management into the PHP package. It must be patched into your PHP source code, and it can be used after compiling and installing PHP. The new version of PHP has integrated php-fpm, it is no longer a third-party package, it is recommended to use. PHP-FPM provides a better PHP process management method, which can effectively control memory and process, and can smoothly reload PHP configuration. It has more advantages than spawn-fcgi, so it is officially included…

Linux system integrates Nginx+Tomcat server environment configuration

With the continuous development of the IT industry, the performance of personal and enterprise applications on the website is also constantly improving. From the previous apache+tomcat integration, weblogic and other common web applications, lighttpd, nginx Constantly being used by enterprises, the combination of nginx+tomcat is becoming more and more widely used. The following is my nginx+Tomcat integration method. I also refer to many articles on the Internet. Thank you! Although there are many nginx+tomcat integration solutions on the Internet, there are good and bad, here is the configuration document that I personally practiced, for everyone to learn and reference! Improve each other! 1. First, we download the source package we need: Tomcat version download, this website integrates download: jdk, please go to the following website to download: https://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/ViewProductDetail-Start?ProductRef=jdk-6u18-oth-JPR@CDS-CDS_Developer Tomcat download address: http://blog.mgcrazy.com/download/apache-tomcat-6.0.30.tar.gz [Nginx-0.8.54 download, nginx download, nginx stable version download] http://blog.mgcrazy.com/download/nginx-0.8.54.tar.gz http://blog.mgcrazy.com/download/pcre-8.01.tar.gz Download to the /usr/src directory. Next we start the installation! First install jdk: chmod o+x jdk* && ./jdk* ;The program package will prompt you to press the Enter key. We can install it according to the prompt. After decompression, the jdk1.6.0_18 folder will be generated in the current directory, mkdir -p /usr/java && mv jdk1.6.0_18 /usr/java/under Add the…

Pseudo-static setup of Nginx and Apache

Apache URL Rewrite converted to NGINX URL Rewrite tool http://www.anilcetin.com/convert-apache-htaccess-to-nginx/ First of all, Apache’s Rewrite rules are not very different, but Nginx’s Rewrite rules are much simpler and more flexible than Apache’s Nginx can use if for conditional matching, and the syntax rules are similar to C if ($http_user_agent ~ MSIE) { rewrite ^(.*)$ /msie/$1 break; } For official documents, please click here Flags of Rewrite Flags can be any of the following: * last – completes processing of rewrite directives, after which searches for corresponding URI and location * break – completes processing of rewrite directives *redirect – returns temporary redirect with code 302; it is used if the substituting line begins with http:// * permanent – returns permanent redirect with code 301 last- After completing the rewrite instruction, search for the corresponding URI and location. It is equivalent to the [L] mark in Apache, which means that the rewrite is completed and no longer matches the following rules. break – Abort Rewirte, do not continue matching. redirect – Returns HTTP status 302 for a Temporary Redirect. permanent- Returns HTTP status 301 for Permanent Redirect. Redirection rules for ZEND Framework: Case 1: Redirect all to /index.php rewrite ^/(.*) /index.php?$1&;…

Nginx server configuration reverse proxy

Inscription: The problem is mainly because the environment where I work often needs to bind hosts. Sometimes I need to bind more than 10, and it is very troublesome to switch between multiple environments. Later, I found that some colleagues used the proxy method to bind them uniformly. I really think it is a recovery It’s a good way, so I conducted a more detailed investigation on proxy tools, and wrote this article. The key problem solved in this article is how to bind hosts through a proxy. The following article is my personal understanding, please correct me if there are any deficiencies or mistakes, thank you! The word agent is believed to be familiar to everyone, and students who are familiar with overpassing the wall must be familiar with it. Hehe, this article does not explain how to find a ladder. I believe everyone has their own way of crossing the sea. To learn a proxy, you must first clarify two concepts: forward proxy/reverse proxy. There are a lot of information about the forward and reverse instructions on Google. Simply understand that the so-called forward is an access from the inside to the outside, and the so-called reverse is…

Nginx configuration file content explanation

----------------nginx Configure gzip compression Under normal circumstances, the size of compressed html, css, js, php, jhtml and other files can be reduced to 25% of the original size, that is to say, the original 100k html is only 25k after compression. This will undoubtedly save a lot of bandwidth and reduce the load on the server. It is relatively simple to configure gzip in nginx In general, just add the following lines of configuration to the http section of nginx.conf gzip on; gzip_min_length 1000; gzip_buffers 4 8k; gzip_types text/plain application/x-Javascript text/css text/html application/xml; restart nginx You can use the webpage gzip detection tool to detect whether gzip is enabled on the webpage http://gzip.zzbaike.com/ —————How to redirect nginx error page error_page 404 /404.html; This 404.html is guaranteed to be in the html directory under the nginx main directory. If you need to jump directly to another address after a 404 error occurs, you can directly set it as follows: error_page 404 http://www.***.net; In the same way, common errors such as 403 and 500 can be defined. Please note that the page size of the 404.html file must exceed 512k, otherwise it will be replaced by the default error page of ie…

Nginx+PHP-fpm environment performance parameter optimization method

1. The bigger the worker_processes, the better (the performance increase is not obvious after a certain number) 2.worker_cpu_affinity All cpus share worker_processes equally than each worker_processes The performance of cross-cpu allocation is better; regardless of the execution of php, the test result has the best performance when the number of worker_processes is twice the number of cpu cores 3. Unix domain socket (the way of shared memory) is better than tcp network port configuration performance Regardless of the backlog, the request speed has an order of magnitude leap, but the error rate exceeds 50% With backlog, the performance is improved by about 10% 4. Adjust the backlog (backlog) of nginx, php-fpm and kernel, connect() to unix: /tmp/php-fpm.socket failed (11: Resource temporarily unavailable) while connecting to upstream error returns will be reduced nginx: The server block of the configuration file listen 80 default backlog=1024; php-fpm: configuration file listen.backlog = 2048 Kernel parameters: /etc/sysctl.conf, cannot be lower than the above configuration net.ipv4.tcp_max_syn_backlog = 4096 net.core.netdev_max_backlog = 4096 5. Increasing the master instance of php-fpm on a single server will increase the processing capacity of fpm and reduce the probability of error reporting and return Multi-instance startup method, using multiple configuration files: /usr/local/php/sbin/php-fpm…

Nginx+Apache environment test load balancing

First prepare a few virtual machines and write down the corresponding configuration 192.168.1.54 ————————>ubuntu11.4+nginx0.8.54 +php5.3.5 +msyql5.1 (load balancing server, php and mysql are not used here) 192.168.1.53 ————————>centos5.5+ apache+php5.3.5+mysql5.1 (web server) 192.168.1.55 ————————>centos5.5+ apache+php5.3.5+mysql5.1 (web server) 1. Simply access different servers according to the request suffix name, modify /etc/nginx/site_available/default It is required that all visits to *.php point to 1.55, and all visits to *.html point to 1.53 server { listen 80; index index.php index.html index.htm; server_namewww.test.com; # key configuration location ~ \.php$ {   proxy_pass http://192.168.1.55; location ~ \.html$ { proxy_pass http://192.168.1.53; } 2. Simple access to different servers by domain name, it seems to be called reverse proxy The nginx configuration of this version is scattered in several files, among which /etc/nginx/nginx.conf is configured as a global configuration, and the /etc/nginx/site_available/default file contains the configuration information of each virtual server, and then /etc /nginx/nginx.conf is included in /etc/nginx/site_available/default Here we have two domain names img.test.com and www.test.com, both point to 192.168.1.54, all visits go to 192.168.1.54 , then 192.168.1.54 Then access different back-end servers according to different domain names, all visits to img.test.com are directed to 192.168.1.53, and all visits to www.test.com are directed to 192.168.1.55 Approach: Configure…

Nginx server configuration reverse proxy and load balancing

nginxReverse proxy load: Environment: There is 1 nginx on the front end as a reverse proxy server (install nginx (listening to port 8080) and apache (listening to port 80)); there are 2 apaches behind it as application servers (listening to port 80) 1. Nginx is used as a reverse proxy server, placed in front of the two Apaches, as the entrance for user access; Nginx only handles static pages, and all dynamic pages (php requests) are delivered to the two apaches in the background for processing. That is to say, we can place the static pages or files of our website in the nginx directory; dynamic pages and database access are reserved on the apache server in the background. 2. There are two methods to achieve load balancing of server cluster. the We assume that the front-end nginx (127.0.0.1:80) only contains a static page index.html; There are two apache servers in the background (localhost:80 and 119.168.136.2:80 respectively), one root directory places the phpMyAdmin folder and test.php (the test code inside is print “server1”;), ​​another root directory only places a test.php (the test code inside is print “server2”;). 1). The simplest example of using nginx as a reverse proxy server; when…

Forwarding settings for Nginx server

Under the .net platform, there are two ways of load balancing that I have deployed so far (iis7 and Nginx). The following uses Nginx as an example to explain the load balancing of the web layer. The first part WEB layer load balancing Introduction: Nginx surpasses Apache’s high performance and stability, making Nginx used as a Web server in China There are also more and more websites on the server, including Sina Blog, Sina Podcast, Netease News and other portal channels, Liujianfang, 56.com, etc., video sharing websites, Discuz! Official Forum, Shuimushe District and other well-known forums, emerging Web 2.0 websites such as Douban, YUPOO photo album, domestic SNS, and Thunder Online. It is said that Nginx can withstand 30,000 concurrent connections. This point has not been tested. In short, Nginx is famous for its high concurrency. Nginx is also a good choice for front-end load balancing, and it has nothing to do with the specific language. The following is how Nginx distributes to IIS Simple process: user visits website (server C) -> server C (no IIS required) Nginx distributes requests to ->A or B or more servers (specific IIS servers) to achieve front-end load The configuration is very simple, as…

How to compile and install Nginx

Nginx can be compiled and run on most Unix like OS, and there is a ported version for Windows. at present The 1.0.0 stable version of Nginx has been released. The development version is 0.9.x, the stable version is 0.8.x, and the historical stable version is 0.7.x. It is recommended to use 0.8 series as production releases. On June 1, 2011, nginx 1.0.4 was released. advantage: In the case of high concurrent connections, Nginx is a good substitute for the Apache server: Nginx is one of the software platforms often chosen by the bosses of the virtual hosting business in the United States. capable of supporting up to The response of 50,000 concurrent connections, thanks to Nginx for choosing epoll and kqueue as the development model for us. Nginx as a load balancing server: Nginx can directly support Rails and PHP programs to serve externally internally, and can also be used as The HTTP proxy server provides external services. Nginx is written in C, and it is much better than Perlbal in terms of system resource overhead and CPU usage efficiency. As a mail proxy server: Nginx It is also a very good mail proxy server (one of the earliest…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索