Nginx: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
=== [http://nginx.org/ Nginx] === | ===[http://nginx.org/ Nginx]=== | ||
Nginx 已被证明具有极高的稳定性、高性能和高可靠性,并提供了一套强大的工具。 | Nginx 已被证明具有极高的稳定性、高性能和高可靠性,并提供了一套强大的工具。 | ||
Line 31: | Line 31: | ||
===典型配置=== | ===典型配置=== | ||
<code>/etc/nginx/ngxin/conf</code><syntaxhighlight lang=" | <code>/etc/nginx/ngxin/conf</code> | ||
<syntaxhighlight lang="bash"> | |||
user nginx; #Use for CentOS | user nginx; #Use for CentOS | ||
#user www-data; #Use for Debian | #user www-data; #Use for Debian |
Revision as of 01:20, 13 May 2020
Nginx
Nginx 已被证明具有极高的稳定性、高性能和高可靠性,并提供了一套强大的工具。
与 Apache 相比, Nginx 具有的优势:
- 轻量
- 占用内存少
- 配置项更丰富
- 高负载下性能更好
Installation
官方 repo 配置 请参考 nginx.org
Configuration
/etc/nginx/nginx.conf
包含全局配置, 任何站点配置请放在 /etc/nginx/conf.d/
目录下.
Performance
- 启用gzip压缩
- 添加upstream响应时间
- 为静态内容设置适当的过期时间
- 在启用HTTPS的站点总是启用HTTP/2
Caching
Security
Nginx 有许多提供Web Application Firewall(WAF)的模块,但是几乎所有模块都需要从源码编译 Nginx.
Naxsi 和 modsecurity是两个流行的选择
典型配置
/etc/nginx/ngxin/conf
user nginx; #Use for CentOS
#user www-data; #Use for Debian
worker_processes auto; #Or set to number of CPU cores
error_log /var/log/nginx/error.log warn;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'
'"$request_time" "$upstream_response_time" $upstream_cache_status';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
}
/etc/nginx/conf.d/example.conf