Install and configure nginx

Source: Internet
Author: User

During nginx compilation, you must first install external support programs such as PCRE and zlib, and then specify the location of these external support programs during nginx compilation and installation. This way, nginx is started every time, these things will be loaded dynamically.

Next we will introduce another way to compile these programs into nginx, so that nginx will not load them dynamically at startup. It can be learned from the ancient spectrum that this method is more efficient than dynamic loading.
Download:
1. wget http://www.openssl.org/source/openssl-1.0.0a.tar.gz
2. wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.10.tar.bz2
3. wget http://www.zlib.net/zlib-1.2.5.tar.bz2
4. wget http://nginx.org/download/nginx-0.8.52.tar.gz

After you extract all of these files, there will be:
1. openssl-0.9.8l
2. pcre-8.00
3. zlib-1.2.3
4. nginx-0.8.30

I put all these directories in/homr/software/. According to the original method, we need to compile and install them in the OpenSSL, PCRE, and zlib directories. Now we don't need them anymore, directly go to the nginx directory.

 

Install build. Sh

# Set nginx root path
Home =/home/raycloud/
Nginx_home = $ home/nginx
Nginx_source = $ home/soft/nginx
# Install path
Install = $ nginx_home
# PCRE Source
PCRE = $ nginx_source/PCRE
# Zlib Source Path
Zlib = $ nginx_source/zlib
# OpenSSL Source Path
OpenSSL = $ nginx_source/OpenSSL
# CPU type
CPU = pentium4

# User
User = 'whoam'

# Group
Group = anygroup

If [! -D $ install]; then
Mkdir-p $ install
Fi
. /Configure -- user = $ user -- group = $ group -- prefix = $ install -- The with-http_gzip_static_module -- With-PCRE = $ PCRE -- With-zlib = $ zlib -- with-http_ssl_module -- With-OpenSSL = $ OpenSSL

You can copy the above shell to sh to install it. This method takes a long time to install, because you need to compile external programs first. It is worth noting that, the-J multi-process method cannot be added to make, but only single-process make can be used. Otherwise, it cannot pass. If your application does not require OpenSSL, you do not need to download OpenSSL and remove it in configure. In addition, nginx's google_perftools_module cannot be compiled in this way, so you must install google_perftools externally.

Nginx. conf configuration

User nobody;
Worker_processes 4;

Error_log/home/raycloud/nginx/error/nginx_error.log crit;
Pid/home/raycloud/nginx/error/nginx. PID;

Worker_rlimit_nofile 65535;

Events {
Use epoll;
Worker_connections 65535;
}

HTTP {
Include mime. types;
Default_type application/octet-stream;

Server_names_hash_bucket_size 128;
Client_header_buffer_size 32 K;
Large_client_header_buffers 4 32 K;
Client_max_body_size 8 m;

Sendfile on;
Tcp_nopush on;

Keepalive_timeout 90;

Tcp_nodelay on;

Gzip on;
Gzip_min_length 1 K;
Gzip_buffers 4 16 K;
Gzip_http_version 1.0;
Gzip_comp_level 2;
Gzip_types text/plain application/X-JavaScript text/CSS application/XML;
Gzip_vary on;

Server {
Listen 80;
SERVER_NAME yourdoamin;

Charset UTF-8;

# Access_log logs/host. Access. Log main;

Access_log off;

Location ~ (\. Shtm) $ {
Proxy_pass http: // 127.0.0.1: 8088;
Proxy_redirect off;
Proxy_set_header host $ host;
Proxy_set_header X-real-IP $ remote_addr;
Proxy_set_header X-forwarded-for $ proxy_add_x_forwarded_for;
Client_max_body_size 10 m;
Client_body_buffer_size 128 K;
Proxy_connect_timeout 1800; // The time-out between the browser and nginx. If the request is long, it can be slightly larger.
Proxy_send_timeouts 1800;
Proxy_read_timeout 1800;
Proxy_buffer_size 4 K;
Proxy_buffers 4 32 K;
Proxy_busy_buffers_size 64 K;
Proxy_temp_file_write_size 64 K;
}

The PCRE can be compiled to support regular expressions, as shown below:

Rewrite ^/img/freetemplate/template ([0-9] +)/([0-9] + )/(. +) $/img/freetemplate/template $1/$3 last;

Location ~ * ^. +. (JPG | JPEG | GIF | PNG | ICO | CSS | HTML | XML | CFM | CFC | AFP | ASP | lasso | PL | py | TXT | FLA | SWF) $ {
Root/test/webroot;
Expires 1D;
}

Location ~ * ^. +. (JS | CSS) $ {
Root/test/webroot;
Expires 2 h;
}

}

}

 

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.