Nginx configuration installation tutorial

Source: Internet
Author: User
: This article mainly introduces the nginx configuration and installation tutorial. if you are interested in the PHP Tutorial, refer to it. Nginx configuration installation tutorial

Nginx ("engine x") is a high-performance HTTP and reverse proxy server and an IMAP/POP3/SMTP proxy server. Nginx was developed by the Rambler.ru site, where Igor Sysoev is the second highest traffic in Russia. The first public version 0.1.0 was released in October 4, 2004. The source code is released in the form of a BSD-like license. it is well known for its stability, rich feature sets, sample configuration files, and low consumption of system resources. Nginx 1.0.4 was released on July 15, June 1, 2011.


Generally, we need to install pcre and zlib first. The former is used to rewrite, and the latter is used to compress gzip.

1. select the source code directory

Selected directory/usr/local/

Cd/usr/local/

2. install 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. 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. 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. install nginx

Nginx generally has two versions: stable version and development version. you can select one of these two versions based on your purpose, the following describes how to install Nginx in 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 the pcre-8.21.

-- With-zlib =/usr/src/zlib-1.2.7 refers to the source code path of the zlib-1.2.7.

6. start

Make sure that Port 80 of the system is not occupied by other programs,

/Usr/local/nginx/sbin/nginx

Check whether startup is successful:

Netstat-ano | grep 80 indicates that the startup is successful.

Open the browser to access the IP address of this machine. if the browser displays Welcome to nginx! Nginx has been installed and runs 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 configurations

# Nginx running Users and Groups

User www;

# Start the process. generally, it is set to be equal to the number of CPUs

Worker_processes 4;

# Global error logs and PID files

Pid/var/run/nginx. pid;

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

Events {

# Epoll is a method in Multiplexing I/O Multiplexing, but it is only used in Linux or later kernels, which can greatly improve nginx performance.

Use epoll;

# Maximum number of concurrent connections of a single backend worker process

Worker_connections 10240;

}

# Set the http server and use its reverse proxy function to provide load balancing support

Http {

Include mime. types;

Default_type application/octet-stream;

Error_page 400 403 500 502 503 x.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 1 k;

Gzip_http_version 1.0;

Gzip_comp_level 2;

Gzip_buffers 4 16 k;

Gzip_proxied any;

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

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

# Gzip_vary on;

Server_name_in_redirect off;

# Set the server list of server load balancer

Upstream portals {

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

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

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

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

}

# Upstream overflow {

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

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

#}

Server {

# Listening on port 8080

Listen 8080;

Server_name 127.0.0.1;

#403 and 404 page redirection addresses

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_timeouts 180;

Proxy_read_timeout 180;

Proxy_buffer_size 64 k;

Proxy_buffers 4 128 k;

Proxy_busy_buffers_size 128 k;

Client_header_buffer_size 16 k;

Large_client_header_buffers 4 64 k;

# Proxy_send_timeout 3 m;

# Proxy_read_timeout 3 m;

# Proxy_buffer_size 4 k;

# Proxy_buffers 4 32 k;

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 10 m;

}

Location =/check.html {

Root/usr/local/nginx/html /;

Access_log off;

}

Location =/50x.html {

Root/usr/local/nginx/html /;

Expires 1 m;

Access_log off;

}

Location =/index.html {

Add_header Vary Accept-Encoding;

# Define the default website root directory location of the server

Root/data/web/html/ebiz;

Expires 10 m;

}

# Define the reverse proxy access name

Location ~ ^/Ecps-portal /*{

# Expires 10 m;

# REDIRECT cluster name

Proxy_pass http: // portals;

# Proxy_pass http: // 172.16.68.134: 8082;

}

Location ~ ^/FetionLogin /*{

# Expires 10 m;

Proxy_pass http: // portals;

# Proxy_pass http: // 172.16.68.134: 8082;

}

# Location ~ ^/Business /*{

# Expires 10 m;

# Proxy_pass http: // 172.16.68.132: 8088;

# Proxy_pass http: // 172.16.68.134: 8082;

#}

Location ~ ^/Rsmanager /*{

Expires 10 m;

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

# The page cache time is 10 minutes.

Expires 10 m;

}

# Set the address for viewing Nginx status

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 10 m;

# Root/data/web/html /;

#}

Location /{

Root/data/web/html/sysMaintain /;

If (! -F $ request_filename ){

Rewrite ^/(. *) $/sysMaintain.html last;

}

}

}

}


The above introduces the nginx configuration and installation tutorial, including the nginx configuration content, hope to be helpful to friends who are interested in the PHP Tutorial.

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.