Nginx basic configuration

Source: Internet
Author: User

Nginx

1. High-Performance HTTP server, supporting up to 20000 concurrent access
2. Reverse Proxy Server for website Acceleration
3. As a front-end Server Load balancer
========================================================== ======================

I. Preparations
# Service httpd stop
# Chkconfig httpd off
Required Software: Development Library, OpenSSL-devel

2. Deploy nginx
1. PCRE: supports regular expressions and address rewriting rewrite
# Tar zxf pcre-8.31.tar.gz
# Cd pcre-8.31
#./Configure & make install
# Ldconfig

2. nginx
# Useradd WWW
# Tar xvf nginx-1.2.2.tar.gz
# Cd nginx-1.2.2
[[Email protected] nginx-1.2.2] #./configure \
> -- User = www \
> -- Group = www \
> -- Prefix =/usr/local/nginx-1.2.2 \
-- With-http_stub_status_module \
-- With-http_sub_module \
-- With-http_ssl_module \
> -- With-PCRE =/usr/src/pcre-8.31 # PCRE source program directory

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

# Make & make install
# Ln-S/usr/local/nginx-1.2.2 // usr/local/nginx

# Tree/usr/local/nginx/
/Usr/local/nginx/
| -- Conf
| -- FastCGI. conf
| -- FastCGI. conf. Default
| -- Fastcgi_params
| -- Fastcgi_params.default
| -- Koi-UTF
| -- Koi-win
| -- Mime. Types
| -- Mime. types. Default
| -- Nginx. conf // main configuration file
| -- Nginx. conf. Default
| -- Scgi_params
| -- Scgi_params.default
| -- Uwsgi_params
| -- Uwsgi_params.default
| '-- Win-UTF
| -- Html
| -- 50x.html
| '-- Index.html
| -- Logs
'-- Sbin
'-- Nginx

3. Start
[[Email protected] ~] #/Usr/local/nginx/sbin/nginx
[[Email protected] ~] # Netstat-tnlp | grep: 80
TCP 0 0 0.0.0.0: 80 0.0.0.0: * Listen 10627/nginx

4. Test
# Links-dump 192.168.9.110
Welcome to nginx!
# Echo "/usr/local/nginx/sbin/nginx">/etc/rc. Local # Start the instance


Ii. Basic nginx Configuration
[[Email protected] ~] # Vim/usr/local/nginx/CONF/nginx. conf
Coremodule nginx kernel module
Eventsmodule event-driven module
Httpcoremodule HTTP kernel module

# Sed-I '/^ [\ t] * #/d;/^ [\ t] * $/D'/usr/local/nginx/CONF/nginx. conf

# Vim/usr/local/nginx/CONF/nginx. conf
Worker_processes 2; # Number of initially started processes (recommended number of CPU cores)
Worker_connections 15000; # maximum number of connections
Server {
Listen 80; # listening port
SERVER_NAME localhost; # site name
Location /{
Root HTML; # The root command specifies the Home Directory of the website (relative to the nginx installation directory)
Index index.html index.htm; # default homepage
}
Error_page 500 502 503 x.html;
Location =/50x.html {
Root HTML;
}
}

Syntax check:
#/Usr/local/nginx/sbin/nginx-T
Nginx: the configuration file/usr/local/nginx/CONF/nginx. conf syntax is OK
Nginx: configuration file/usr/local/nginx/CONF/nginx. conf test is successful


Reload nginx:
[[Email protected] ~] # Pgrep nginx
5693
5757

[[Email protected] ~] # Kill-HUP 5693
[[Email protected] ~] # Pgrep nginx
5693
5787

#/Usr/local/nginx/sbin/nginx-s reload

#/Usr/local/nginx/html/# default site home directory
# Echo "Welcome to Jeffery nginx">/usr/local/nginx/html/index.html
[[Email protected] ~] # Elinks-dump 192.168.9.110
Welcome to Jeffery nginx




========================================================== ======================

Troubleshooting:
[[Email protected] ~] #/Usr/local/nginx/sbin/nginx-T
/Usr/local/nginx/sbin/nginx: Error while loading shared libraries: libpcre. so.1: cannot
Open shared object file: no such file or directory


Compile nginx to specify -- With-PCRE =/usr/src/pcre-8.31 to specify the source code path for the pcre-8.31.

========================================================== ======================

This article is from the "Jeffery blog" blog, please be sure to keep this source http://oceanszf.blog.51cto.com/6268931/1539137

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.