Nginx
nginx [engine x] is an HTTP and reverse proxy server, a mail proxy server, and a generic TCP/UDP proxy server, originally written by Igor Sysoev. For a long time, it has been running on many heavily loaded Russian sites including Yandex, Mail.Ru, VK, and Rambler. According to Netcraft, nginx served or proxied 25.64% busiest sites in April 2016. Here are some of the success stories: Netflix, Wordpress.com, FastMail.FM.
The sources and documentation are distributed under the 2-clause BSD-like license.
Commercial support is available from Nginx, Inc.
Nginx是一款轻量级的Web处事器/反向署理处事器及电子邮件(IMAP/POP3)署理处事器,由俄罗斯工程师Igor
Sysoev开拓,供俄国大型进口网站及搜索引擎Rambler利用.其源代码以BSD-like协议宣布.
其特点是内存占用少,并发本领强,
因此被海内许多大型网站(如京东/淘宝)回收.
(主页/先容/文档).
编译安装
目次 | 描写 |
---|---|
conf | nginx设置文件 |
html | 网页文件 |
logs | nginx日志文件 |
sbin | nginx可执行文件 |
/usr/local/nginx/sbin/nginx
启动, Nginx默认占用80端口,可在nginx.conf中变动.
Nginx信号
关于Linux信号相关常识, 可参考系列博客Linux信号实践, 在此, 我们仅先容Nginx捕捉的几个信号.
nginx can be controlled with signals.
信号名 | 浸染 |
---|---|
TERM/INT | fast shutdown |
QUIT | graceful shutdown |
HUP | changing configuration, keeping up with a changed time zone , starting new worker processes with a new configuration, graceful shutdown of old worker processes |
USR1 | re-opening log files |
USR2 | upgrading an executable file |
WINCH | graceful shutdown of worker processes |
以上信号浸染亦可通过编译出的nginx二进制文件实现:
To start nginx, run the executable file. Once nginx is started,
it can be controlled by invoking the executable with the -s
parameter. Use the following syntax:
nginx -s signal
设置
"hljs-preprocessor">#运行处事的用户及用户组
#user nobody;
#事情历程数(一般配置为CPU数*焦点数)
worker_processes ;
#全局错误日志(位置/级别)
#error_log logs/ "hljs-keyword">error.log;
#error_log logs/ "hljs-keyword">error.log notice;
#error_log logs/ "hljs-keyword">error.log info;
#PID文件
#pid logs/nginx.pid;
#事情模式及毗连数上限
events {
# 回收epoll举办IO复用
# use epoll;
# 单历程所答允的最大毗连数
worker_connections ;
}
http {
include mime.types;
default_type application/octet-stream;
"hljs-preprocessor">#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
"hljs-preprocessor"># '$status $body_bytes_sent "$http_referer" '
"hljs-preprocessor"># '"$http_user_agent" "$http_x_forwarded_for"';
"hljs-preprocessor">#access_log logs/access.log main;
#是否激活sendfile()函数
sendfile on;
"hljs-preprocessor">#将HTTP响应头压缩到一个包中发送,仅在sendfile开启时才气利用
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout ;
#开启gzip模块
#gzip on;
#设定虚拟主机,默认监听80端口,可设置多个
server {
listen ;
server_name localhost;
#charset koi8-r;
"hljs-preprocessor">#access_log logs/host.access.log main;
# 页面存放位置
location / {
# 页面存放根目次
root html;
# 默认页面
index index.html index.htm;
}
"hljs-preprocessor">#error_page 404 /404.html;
"hljs-preprocessor"># redirect server "hljs-keyword">error pages to the static page /50x.html
#
error_page /x.html;
location = /x.html {
root html;
}
"hljs-preprocessor"># proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ .php$ {
"hljs-preprocessor"># proxy_pass http://127.0.0.1;
#}
"hljs-preprocessor"># pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ .php$ {
"hljs-preprocessor"># root html;
"hljs-preprocessor"># fastcgi_pass 127.0.0.1:9000;
"hljs-preprocessor"># fastcgi_index index.php;
"hljs-preprocessor"># fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
"hljs-preprocessor"># include fastcgi_params;
#}
"hljs-preprocessor"># deny access to .htaccess files, "hljs-keyword">if Apache's document root
"hljs-preprocessor"># concurs with nginx's one
#
#location ~ /.ht {
# deny all;
#}
}
"hljs-preprocessor"># another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
"hljs-preprocessor"># listen somename:8080;
"hljs-preprocessor"># server_name somename alias another.alias;
# location / {
# root html;
"hljs-preprocessor"># index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
"hljs-preprocessor"># listen 443 ssl;
"hljs-preprocessor"># server_name localhost;
"hljs-preprocessor"># ssl_certificate cert.pem;
"hljs-preprocessor"># ssl_certificate_key cert.key;
"hljs-preprocessor"># ssl_session_cache shared:SSL:1m;
"hljs-preprocessor"># ssl_session_timeout 5m;
"hljs-preprocessor"># ssl_ciphers HIGH:!aNULL:!MD5;
"hljs-preprocessor"># ssl_prefer_server_ciphers on;
# location / {
# root html;
"hljs-preprocessor"># index index.html index.htm;
# }
#}
}
Server
在Nginx内可设置虚拟主机, 只需在nginx.conf中添加一个server元素: