Nginx学习0 - Hello World
简介
NGINX is a free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server. NGINX is known for its high performance, stability, rich feature set, simple configuration, and low resource consumption.
NGINX is one of a handful of servers written to address the C10K problem. Unlike traditional servers, NGINX doesn’t rely on threads to handle requests. Instead it uses a much more scalable event-driven (asynchronous) architecture. This architecture uses small, but more importantly, predictable amounts of memory under load. Even if you don’t expect to handle thousands of simultaneous requests, you can still benefit from NGINX’s high-performance and small memory footprint. NGINX scales in all directions: from the smallest VPS all the way up to large clusters of servers.
–官网
安装
OS环境
1 | $ uname -a |
Prerequisite
- gcc
- g++
- openssl
- 需要安装 PCRE库,否则 ./configure: error: the HTTP rewrite module requires the PCRE library.
1 | sudo apt-get install libpcre3 libpcre3-dev |
下载&安装
1 | wget http://nginx.org/download/nginx-1.10.0.tar.gz |
运行 ./configure 完成后输出如下:
1 | Configuration summary |
接下来 make, make install 产生可执行文件,并且拷贝到对应的目录
1 | ➜ nginx-1.10.0 sudo make install |
安装完成后,可以熟悉下对应的nginx命令。
1 | ➜ nginx-1.10.0 sudo /usr/local/nginx/sbin/nginx & |
配置HTTP模块服务静态内容
得益于Nginx的很多默认配置项,配置HTTP模块服务静态内容很简单,在nginx.conf文件中设置server,location块配置。
运行结果如下: