Why choose Nginx
Simple Application Server
USD1.00 New User Coupon
* Only 3,000 coupons available.
* Each new user can only get one coupon(except users from distributors).
* The coupon is valid for 30 days from the date of receipt.
Why choose Nginx? Because it has the following characteristics:
1. Processing response requests quickly
Under normal circumstances, a single request will get a faster response. During peak periods, Nginx can respond to requests faster than other
Web servers.
2. High concurrent connection
With the rapid development of the Internet and the ever-increasing number of Internet users, some large companies and websites need to face high concurrent requests. If there is a
Server that can withstand more than 100,000 concurrent requests at a peak, it will definitely be favored by everyone. In theory, the upper limit of concurrent connections supported by Nginx depends on your memory, and 100,000 is far from being capped.
3. Low memory consumption
In general, 10,000 inactive HTTP Keep-Alive connections consume only 2.5MB of memory in Nginx, which is the basis for Nginx to support high concurrent connections.
4. High reliability:
Nginx is a highly reliable
web server, which is also the basic condition for why we choose Nginx. Now many websites are using Nginx, which is enough to illustrate the reliability of Nginx. High reliability comes from the excellent design of its core framework code, the simplicity of module design, and these modules are very stable.
5. High scalability
The design of Nginx is extremely extensible. It is completely composed of multiple modules with different functions, different levels, different types and extremely low coupling. This design creates a huge third-party module of Nginx.
6. Hot deployment
The separation design of the master management process and the worker process makes Nginx hot-deployable and can upgrade the Nginx executable file under the premise of 7 × 24 hours of uninterrupted service. It is also possible to modify configuration files and replace log files without stopping the service.
7. Free BSD license agreement
The BSD license agreement not only allows users to use Nginx for free, but also allows users to modify the Nginx source code, and also allows users to use it for commercial purposes.
How to use Nginx
Nginx installation:
Different system dependent packages may be different, such as pcre, zlib, openssl, etc.
Get the latest version of Nginx at http://nginx.org/en/download.html.
Unzip the nginx-xx.tar.gz package.
Enter the unzipped directory and execute ./configure
make & make install
If the above dependent modules cannot be found during installation, use --with-openssl=<openssl_dir>, --with-pcre=<pcre_dir>, --with-zlib=<zlib_dir> to specify the dependent module directory. If it has been installed, the path here is the installation directory; if it is not installed, this path is the path to compile and install the package, and Nginx will execute the default compile and installation of the module.
After starting Nginx, enter http://localhost in the browser to verify whether the installation has started successfully.
Nginx configuration example:
After the installation is complete, there are the following configuration files in the configuration directory conf, filtering out the xx.default configuration:
ubuntu: /opt/nginx-1.7.7/conf$ tree |grep -v default
.
├── fastcgi.conf
├── fastcgi_params
├── koi-utf
├── koi-win
├── mime.types
├── nginx.conf
├── scgi_params
├── uwsgi_params
└── win-utf
Except for nginx.conf, other configuration files generally only need to be provided by default.
nginx.conf is the main configuration file, the default configuration after uncommented content is shown in the following figure:
worker_process # Indicates the number of worker processes, generally set to the number of cores of the cpu
worker_connections # Indicates the maximum number of connections for each worker process
server{} # block defines the virtual host
listen # listening port
server_name # monitor domain name
location {} # is used to configure the matching URI, URI is the "/uri/" in the syntax
location /{} # matches any query, because all requests start with /
root # Specify the resource search path corresponding to uri, where html is a relative path, and the full path is
# /opt/nginx-1.7.7/html/
index # Specify the name of the index file on the home page, you can configure multiple, separated by spaces. If more
#, search in the order of configuration.
Real use case
It can be seen from the configuration that Nginx monitors port 80, the domain name is localhost, and the root path is the html folder (my installation path is /opt/nginx-1.7.7, so /opt/nginx-1.7.7/html), The default index file is index.html, and the index.htm server error redirects to the 50x.html page.
You can see that /opt/nginx-1.7.7/html/ has the following files:
ubuntu:/opt/nginx-1.7.7/html$ ls
50x.html index.html
This is the reason why the welcome page can be displayed by entering http://localhost in the browser above. Actually, the file /opt/nginx-1.7.7/html/index.html is accessed.