CENTOS compile and install Nginx
1. Download a package from nginx official website, the download address is:http://nginx.org/en/download. html 2. WinSCP (ftp upload tool).exe FTP upload tool is uploaded to CentOS 3. I first create a directory and put together the installation packages to be used. #mkdir /home/ #tar zxf nginx-1.4.1.tar.gz #cd nginx-1.4.1 4. Install the pcre development package #yum install -y pcre-devel 5. If the installation error appears below is the lack of a compilation environment. Install the tools and libraries required to compile the source code ./configure: error: C compiler cc is not found #yum install gcc gcc-c++ ncurses-devel perl 6. Install cmake, download the source code from http://www.cmake.org and compile and install #yum -y install make gcc gcc-c++ ncurses-devel #yum -y install zlib zlib-devel 7. If you need ssl function, you need openssl library #yum -y install openssl openssl –devel 8. Install nginx #cd nginx-1.4.1 #./configure –prefix=/opt/nginx #make #make install 9. Start the service #/opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf 10. Stop service #/opt/nginx/sbin/nginx -s stop 11. Check port occupancy #netstat -tunlp 12. If other machines cannot be accessed, the solution is as follows: #/sbin/iptables -I INPUT -p tcp –dport 80 -j ACCEPT Then save: #/etc/rc.d/init.d/iptables save Restart the firewall #/etc/init.d/iptables restart
PHP5.4 or introduce PHP-FPMnginx to run PHP more easily
I have introduced Nginx + PHP-FPM + APC = a wonderful combination before. Recently, it has been reported that PHP5.4 will likely include the PHP-FPM (PHP FastCGI Process Manager) patch in the kernel. This news came as a great surprise to those who run PHP on the nginx server platform. Maybe you have this question: “What is PHP-FPM? Why should we pay attention to it?” PHP-FPM is a patch written for the PHP core to handle starting, stopping and restarting FastCGI processes as needed. This is a very critical function, because nginx can only interface with PHP through FastCGI. nginx cannot load all the PHP environment into itself like Apache can. Nginx running PHP through FastCGI has obvious advantages over Apache containing the PHP environment: ◆Low memory usage (because nginx does not need to load the entire PHP environment when running alone). ◆ Easily manage user permissions (because PHP can manage different users in your server process). ◆When PHP crashes, nginx can run normally. Its downside is that it requires mod_php, nginx, PHP and FastCGI to be installed and set up in contrast. In the past, this installation required co-opting the spawn-fcgi script from the LightTPD project and using it…
Nginx configuration file nginx.conf Chinese detailed explanation (summary)
the PS: Nginx has been used for two or three years, and now I often encounter some very basic questions from new users, and I don’t have time to answer them one by one. I spent some time this afternoon, combined with my own experience, to configure the main configuration of Nginx Share the parameter description, and also refer to some network content. This is the most complete Chinese description of Nginx configuration parameters. For more detailed module parameters, please refer to: http://wiki.nginx.org/Main the the #Define the user and user group for Nginx to run user www www; the #nginx process number, it is recommended to set it equal to the total number of CPU cores. worker_processes 8; the #Global error log definition type, [ debug | info | notice | warn | error | crit ] error_log ar/loginx/error.log info; the #Process file pid ar/runinx.pid; the #The maximum number of file descriptors opened by an nginx process, the theoretical value should be the maximum number of open files (system value ulimit -n) divided by the number of nginx processes, but nginx allocation requests are not uniform, so it is recommended to use ulimit -n The value remains the same. worker_rlimit_nofile…
Why is the performance of Nginx much higher than that of Apache?
This is due to Nginx using the latest epoll (Linux 2.6 kernel) and kqueue (freebsd) network I/O model, Apache, on the other hand, uses the traditional select model. At present, Squid and Memcached, which can withstand high concurrent access under Linux, all use the epoll network I/O model. To deal with the read and write of a large number of connections, the select network I/O model adopted by Apache is very inefficient. Let’s use a metaphor to analyze the difference between the select model adopted by Apache and the epoll model adopted by Nginx: Suppose you are studying in a university, and there are many rooms in the dormitory building where you live, and your friends want to come to you. The dormitory aunt in the select version will take your friends to search from room to room until they find you. The dormitory aunt of the epoll version will first write down the room number of each student, When your friends come, you only need to tell your friends which room you live in, instead of taking your friends all over the building to find someone. If 10,000 people come and they all want to find their classmates who…
Primary article on large-scale website technology practice: building a reverse proxy server with Nginx
1. Reverse proxy: the “broker” of the Web server 1.1 Initial impression of reverse proxy Reverse proxy (Reverse Proxy) method refers to using a proxy server to accept connection requests on the Internet, and then forwards the request to a server on the internal network, and transfers the connection request from the server The results obtained on the Internet are returned to the client requesting a connection on the Internet. At this time, the proxy server acts as a server to the outside world. It can be seen from the above figure that the reverse proxy server is located in the website computer room, and the proxy website web server receives the Http request and forwards the request. 1.2 The role of reverse proxy ①Protect website security: Any request from the Internet must first pass through the proxy server; ②Accelerating web requests by configuring the cache function: can cache some static resources on the real web server to reduce the load pressure on the real web server; ③Realize load balancing: Act as a load balancing server to distribute requests in a balanced manner, and balance the load pressure of each server in the cluster; 2. Getting to know Nginx for…
nginx static compression (ngx_http_gzip_static_module)
nginx The way nginx implements static compression is actually like apache gzip compression. This kind of compression is a common thing for us. Let me introduce some methods below. When building squid web page acceleration, large css or js should be compressed and then cached, which can reduce the download volume and improve the page response speed. If you are using a version earlier than squid 3.0 and using ngnix server, you may encounter the following problems: If you open the page directly without squid, the client will return a compressed state. If you enable squid acceleration, you will find that the downloaded page is not compressed state. This is mainly caused by not starting the static caching module (ngx_http_gzip_static_module) of ngnix. Open the static cache problem is solved nginx compile options 1 ./configure –with-http_gzip_static_module configure nginx 1 2 3 4 5 6 7 8 9 10 11 12 13 14 gzip_static on; gzip_http_version 1.1; gzip_proxied expired no-cache no-store private auth; gzip_disable “MSIE [1-6] .”; gzip_vary on; #Cannot find the pre-compressed file, perform dynamic compression gzip on; gzip_min_length 1000; gzip_buffers 4 16k; gzip_comp_level 5; gzip_types text/plain application/x-Javascript text/css application/xml; #gzip public configuration gzip_http_version 1.1 gzip_proxied expired no-cache no-store private auth;…
Upsync: Weibo open source dynamic traffic management solution based on Nginx container
Editor’s note: High-availability architecture sharing and dissemination of articles with typical significance in the field of architecture, this article is shared by Yao Sifang in the high-availability architecture group. For reprinting, please indicate that it is from the high-availability architecture public account “ArchNotes”. Yao Sifang, senior technical expert of Sina Weibo, technical director of Weibo platform architecture group. Joined Sina Weibo in 2012 and participated in several key projects such as Weibo Feed architecture upgrade, platform service transformation, and hybrid cloud. He is currently the technical leader of the Weibo platform architecture group and is responsible for the research and development of the platform’s public infrastructure. He once shared the technology of “Sina Weibo High Performance Architecture” at QCon, focusing on the direction of high-performance architecture and service middleware. Business background and problems used by Nginx Nginx With its ultra-high performance and stability, it has been widely used in the industry, and Nginx is widely used on the seventh floor of Weibo. Combined with the health check module of Nginx and the dynamic reload mechanism, the upgrade and expansion of the service can be almost lossless. At this time, the frequency of expansion is relatively low, and in most cases…
A lightweight RPC framework that supports hundreds of billions of Weibo calls: Motan
Editor’s note: High-availability architecture sharing and dissemination of articles with typical significance in the field of architecture, this article is shared by Zhang Lei in the high-availability architecture group. For reprinting, please indicate that it is from the high-availability architecture public account “ArchNotes”. Zhang Lei, technical expert of Sina Weibo, technical director of MotanRPC framework. Joined Sina Weibo in 2013, participated in several key projects such as Weibo RPC service and hybrid cloud as a core technical member, and is currently responsible for the maintenance and architecture improvement of the MotanRPC framework. Focus on high-availability architecture and service middleware development direction. ” In 2013, the Weibo RPC framework Motan was born in the careful design and hard work of the senior masters (Fulin, fishermen, wheat, Wang Zhe, etc.). Constantly improving, Motan has been widely used in the Weibo platform, completing nearly 100 billion calls for hundreds of services every day.” —— Zhang Lei With the rapid development of Weibo container deployment and hybrid cloud platform, RPC is becoming more and more important in the process of micro-service, and the demand for RPC has also undergone some changes. Today I will mainly introduce Motan, the Weibo RPC framework, and some improvements…
Nginx source code analysis: core module analysis and common problems
Guide: Many architects want to understand and master high-performance server development. One way to do this is to read the good source code, where nginx is an industry-renowned implementation of a high-performance web server. How to effectively read and understand nginx? This article introduces core modules such as HTTP and common problems in reading nginx source code, helping everyone to better read and understand the implementation of nginx key modules. Chen Ke, with ten years of experience in the industry, has worked as a development engineer & architect in Zhejiang Telecom, Alibaba, Huawei, and Wuba Tongcheng. He is currently responsible for the back-end architecture and operation and maintenance of Helijia. Blog address: http://www.dumpcache.com/wiki/doku.php After Nginx parses the request line and request header, it defines a total of eleven stages, which are introduced as follows How the HTTP module works Eleven phase definitions of HTTP processing typedef enum { NGX_HTTP_POST_READ_PHASE = 0, // Read request content phase NGX_HTTP_SERVER_REWRITE_PHASE, // Server request address rewriting phase NGX_HTTP_FIND_CONFIG_PHASE, // Configuration lookup phase NGX_HTTP_REWRITE_PHASE, // Location request address rewriting phase NGX_HTTP_POST_REWRITE_PHASE, // request address rewrite submission phase NGX_HTTP_PREACCESS_PHASE, // access permission check preparation…
Nginx Series Two (Installation and Startup and nginx.conf Configuration Analysis)
The installation of Nginx is relatively simple. The installation provided under Windows is a zip package. It can be installed after decompression directly, and the nginx server can be started by running nginx.exe under its installation directory For the linux version, you need to execute the following command For the above commands, ./configure is a tool for generating makefiles in linux, and the general commands are: ./configure –prefix=/home/vf/usr/local/nginx –with-http_gzip_static_module –with-http_ssl_module –with-http_stub_status_module –with-http_sub_module –with-http_realip_module –with-http_realip_module –add-module=/home/vf/usr/local/nginx-sticky-module The more important one is –prefix, which is a prefix that represents the installation location of the program. The follow-up is to pass several key parameters. For these parameters, the configuration file is modified when nginx is installed. For details, please refer to the configuration document of Nginx. After the ./configure tool, the makefile is generated, which is the specified file for linux source code installation, and then make is executed. The make command compiles according to the makefile and does not install it. There may be some errors in this step. Compare An obvious error is the absence of the PCRE library, which needs to be installed again through yum or apt-get: ./configure: error: the HTTP rewrite…