Nginx Configuration Installation Tutorial

Source: Internet
Author: User
Nginx Configuration Installation Tutorial

Nginx ("Engine x") is a high- performance HTTP and reverse proxy Server, also a imap/pop3/smtp proxy Server. Nginx was developed by Igor Sysoev for the second rambler.ru site of Russian traffic, the first public version 0.1.0 released in 2004 year ten months 4 days. It publishes the source code in the form of a BSD license, which is known for its stability, rich feature set, sample configuration files, and consumption of low system resources. 6 months 1 days,nginx 1.0.4 released.


Generally we need to first install pcre, Zlib, the former in order to rewrite rewrite, the latter in order to gzip compression.

1. Select the source directory

Selected directory /usr/local/

cd/usr/local/

2. Installing the 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. Installing 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. Install SSL

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. Installing nginx

Nginx generally has two versions, which are stable version and development version, you can choose one of these two versions according to your purpose, the following is the installation of Nginx to /usr/local/nginx Detailed steps under the 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 pcre-8.21 source path.

--with-zlib=/usr/src/zlib-1.2.7 refers to the zlib-1.2.7 source path.

6. Start

Make sure that the port of the system is not occupied by other programs.

/usr/local/nginx/sbin/nginx

Check whether the startup was successful:

netstat-ano|grep Results Input description started successfully

Open the browser to access the IPof this machine if the browser appears Welcome to nginx! Indicates that Nginx is 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 Nginx Configuration

#nginx running users and groups

User www www;

# START Process , usually set into and CPU equal number of

Worker_processes 4;

# Global error log and PID file

Pid/var/run/nginx.pid;

Error_log/var/log/nginx/error.log;

Events {

#epoll is one way in multiplexed IO (I/O multiplexing) , but only for linux2.6 above the core , can greatly improve The performance of Nginx

Use Epoll;

# Single Background worker Process Maximum number of concurrent links for a process

Worker_connections 10240;

}

# setting http server, using its reverse proxy feature to provide load balancing support

HTTP {

Include Mime.types;

Default_type Application/octet-stream;

Error_page 403 502 503 504/50x.html;

Index index.html index.shtml

AutoIndex off;

Fastcgi_intercept_errors on;

Sendfile on;

# These are good default values.

Tcp_nopush on;

Tcp_nodelay off;

# Output Compression saves bandwidth

gzip off;

#gzip_static on;

#gzip_min_length 1k;

Gzip_http_version 1.0;

Gzip_comp_level 2;

Gzip_buffers 4 16k;

Gzip_proxied any;

Gzip_disable "MSIE [1-6]\.";

Gzip_types text/plain text/html text/css application/x-javascript application/xml application/xml+rss text/javascript ;

#gzip_vary on;

Server_name_in_redirect off;

# set the server list for load Balancing

Upstream Portals {

Server 172.16.68.134:8082 max_fails=2 fail_timeout=30s;

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 172.16.68.137:8082 max_fails=2 fail_timeout=30s;

}

#upstream Overflow {

# server 10.248.6.34:8090 max_fails=2 fail_timeout=30s;

# server 10.248.6.45:8080 max_fails=2 fail_timeout=30s;

#}

server {

# listening on the 8080 Port

Listen 8080;

server_name 127.0.0.1;

#403,404 page REDIRECT Address

Error_page 403 = http://www.e100.cn/ebiz/other/217/403.html;

Error_page 404 = http://www.e100.cn/ebiz/other/218/404.html;

Proxy_connect_timeout 90;

Proxy_send_timeout 180;

Proxy_read_timeout 180;

Proxy_buffer_size 64k;

Proxy_buffers 4 128k;

Proxy_busy_buffers_size 128k;

Client_header_buffer_size 16k;

Large_client_header_buffers 4 64k;

#proxy_send_timeout 3m;

#proxy_read_timeout 3m;

#proxy_buffer_size 4k;

#proxy_buffers 4 32k;

Proxy_set_header Host $http _host;

Proxy_max_temp_file_size 0;

#proxy_hide_header Set-cookie;

# if ($host! = ' www.e100.cn ') {

# 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;

# define the Default Web site root location for the server

root/data/web/html/ebiz;

Expires 10m;

}

# Define reverse proxy access name

Location ~ ^/ecps-portal/* {

# expires 10m;

# REDIRECT Cluster name

Proxy_pass http://portals;

#proxy_pass http://172.16.68.134:8082;

}

Location ~ ^/fetionlogin/* {

# expires 10m;

Proxy_pass http://portals;

#proxy_pass http://172.16.68.134:8082;

}

#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;

}

# Define the page suffix for nginx processing

Location ~* (. *) \. (JPG|GIF|HTM|HTML|PNG|JS|CSS) $ {

root/data/web/html/;

# Page cache time is ten minutes

Expires 10m;

}

# Settings View Nginx address of the state

Location ~* ^/nginxstatus/{

Stub_status on;

Access_log off;

Allow 10.1.252.126;

Allow 10.248.6.49;

Allow 127.0.0.1;

Deny all;

}

# error_page 405 = 200 @405;

# location @405

# {

# Proxy_pass http://10.248.6.45:8080;

# }

Access_log/data/logs/nginx/access.log combined;

Error_log/data/logs/nginx/error.log;

}

server {

Listen 8082;

server_name _;

Location =/check.html {

root/usr/local/nginx/html/;

Access_log off;

}

}

server {

Listen 8088;

server_name _;

Location ~ ^/* {

root/data/web/b2bhtml/;

Access_log off;

}

}

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;

}

}

}

}


The above describes the Nginx configuration installation tutorial, including the Nginx configuration content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.