Home > Article > Backend Development > nginx installation
Nginx installation and deployment
Nginx ("engine x") is a high-performance HTTP and reverse proxy server, and is also an IMAP/POP3/SMTP proxy server. Nginx is powered by Igor Sysoev was developed for the second most visited Rambler.ru site in Russia. The first public version 0.1.0 was released on 2004year10month4day. It releases its source code under a BSD-like license and is known for its stability, rich feature set, sample configuration files, and low system resource consumption. 2011year6month1day,nginx 1.0.4released.
Generally we need to install pcre and zlib first, the former for rewriting rewrite and the latter for gzip compression.
1.Select the source code directory
Select the directory /usr/local/
cd /usr/local/
2. Install PCRE Library
cd /usr/local/
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.21.tar.gz
tar - zxvf pcre-8.21.tar.gz
cd pcre-8.21
./configure
make
make install
3.Install the zlib library
cd /usr/local/
wget http://zlib.net/zlib-1.2.8.tar.gz
tar -zxvf zlib-1.2.8.tar.gz cd zlib-1.2.8
./configure
make
make install
4.installssl
cd /usr/local /
wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
tar -zxvf openssl-1.0.1c.tar.gz
. /config
make
make install
5.installnginx
Nginx Generally there are two versions, namely the stable version and the development version , you can choose one of these two versions according to your purpose. The following are the detailed steps to install Nginx into the /usr/local/nginx directory:
cd /usr/ local/
wget http://nginx.org/download/nginx-1.2.8.tar.gz
tar -zxvf nginx-1.2.8.tar.gz
cd nginx -1.2.8
./configure --prefix=/usr/local/nginx
make
make install
--with -pcre=/usr /src/pcre-8.21 refers to the source code path of pcre-8.21 .
--with-zlib=/usr/src/zlib-1.2.7 refers to the source code path of zlib-1.2.7 .
6.Start
Make sure the system’s 80port is not occupied by other programs,
/usr/local/nginx/sbin/nginx
Check if startup is successful :
netstat -ano|grep 80 If you enter the result, it means the startup is successful
Open the browser to access the IP of this machine. If the browser displays Welcome to nginx! , it means Nginx has been installed and running successfully.
7.Restart
/usr/local/nginx/sbin/nginx –s reload
8.Modify the configuration file
cd /usr/local/ nginx/conf
vi nginx.conf
9.Common configuration
#nginxRunning user and group
user www www;
#Start the process , are usually set to be equal to the number of cpu
worker_processes 4; PID
File
pid /var/run/nginx.pid;error_log /var/log/nginx/error.log;
events {
O p#EPOLL
is a way in multiple ways to reuse Io (I/O Multiplexing) , but only for kernels above linux2.6, can greatly improve the performance of nginxuse epoll; Number of links sent
off links}
# Set up the http server and use its reverse proxy function to provide load balancing support
http {
application/octet-stream; less autoindex off; on;
# These are good default values.
tcp_nopush on;
tcp_nodelay off;
# output compression saves bandwidth
gzip_comp_level 2; gzip_disable "MSIE [1-6].";
gzip_types text/plain text/html text/css application/x-javascript application/xml application/xml+rss text/javascript;
#Set load Balanced server list
upstream portals {
server 172.16.68.135:8082 max_fails=2 fail_timeout=30s;
server 172.16.68.136:8082 max_fails=2 fail_timeout=30s;
# Server 10.248.6.34:8090 max_fails=2 fail_timeout=30s;
Server {
8 Listen 8080;
Server_name 127.0.0.1;
#403, 404 page redirection address error_page 403 = http://www.e100.cn/ ebiz/other/217/403.html;
oxy_connect_timeout 90;
; X proxy_ream_timeout 180;
Proxy_buffer_size 64k; proxy_buffers 4 128K;
proxy_busy_Size 128k;
size 16k; 1 L Large_Client_header_buffers 4 64K;
#Proxy_send_timeout 3M;
#Proxy_ream_timeout 3M;
#proxy_buffer_size 4K;
#Proxy_buffers 4 32K;;;
proxy_set_header proxy_set_header er Set-Cookie; I#REWRITE ^/(.*) $ Http://www.e100.cn/ $1 permanent;
# }
location / {
deny all;
}
location ~ ^/resource/res/img/blue/space.gif {
proxy_pass http://tecopera;
}
location = / {
rewrite ^(.*)$ /ebiz/event/517.html last;
}
location = /ebiz/event/517.html {
add_header Vary Accept-Encoding;
root /data/web/html;
expires 10m;
}
location = /check.html {
root /usr/local/nginx/html/;
access_log off;
}
location = /50x.html {
root /usr/local/nginx/html/;
expires 1m;
access_log off;
}
location = /index.html {
add_header Vary Accept-Encoding;
#定义服务器的默认网站根目录位置
root /data/web/html/ebiz;
expires 10m;
}
#定义反向代理访问名称
location ~ ^/ecps-portal/* {
# expires 10m;
#Redirect cluster name
proxy_pass http://portals; location /fetionLogin/* {
#proxy_pass http://172.16.68.134:8082;
I #Location ~ ^/Business/* {
##Expires 10M;
#Proxy_pass http://172.16.68.132:8088;
##proxy_pass http://172.16. 68.134: 8082;
#}
Location ~ ^/RSManager/* {
Expires 10m;
root/data/web/;
#Proxy_pass http://rsm;
tm|html|png|js|css )$ {
#The page cache time is 10minutes # Set the address to view the status of Nginx ~ Location ~* ^/ nginxstatus/ { stub_status on; access_log off; allow 10.1.252.126; Allow 10.248.6.49; all 127.0.0.1; deny all; ; 248. 6.45:8080; location = /check.html { /; access_log off; server_name _; /* { } } server { listen 9082; server_name _; # location ~ ^/resource/* { # expires 10m; # root /data/web/html/; # } location / { root /data/web/html/sysMaintain/; if (!-f $request_filename) { rewrite ^/(.*)$ /sysMaintain.html last; } } } }
以上就介绍了nginx 安装,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。