/etc/Nginx/Nginx.conf, /usr/local/etc/Nginx/Nginx.conf, 或者 /usr/local/Nginx/conf/Nginx.conf
gzip on;
worker_processes 2; # directive in the global context http { # http context gzip on; # directive in http context server { # server context listen 80; # directive in server context } }
gzip on; gzip off; # illegal to have two normal directives in the same context server { location /downloads { gzip off; } location /assets { # gzip is in here } }
error_log /var/log/Nginx/error.log; error_log /var/log/Nginx/error_notive.log notice; error_log /var/log/Nginx/error_debug.log debug; server { location /downloads { # this will override all the parent directives error_log /var/log/Nginx/error_downloads.log; } }
server { rewrite ^ /foobar; location /foobar { rewrite ^ /foo; rewrite ^ /bar; } }
执行服务器重写,重写从 /sample 到 /foobar。
然后匹配位置 /foobar。
执行第一个st位置重写,从/foobar重写到/foo。
执行第二个nd位置重写,从/foo重写到/bar。
server { location / { return 200; return 404; } }
# Global context ... ... # http context http{ ... ... # Server context server { listen 80; server_name example.com; ... ... # Location context location / { root /var/www/html; try_files $uri $uri/ =404; ... ... } } # Server context server { ... ... # Location context location / { ... ... } } ... ... }
user Nginx; worker_processes auto; pid /run/Nginx.pid; ... ...
# main context events { # events context worker_connections 768; multi_accept on; } ... ...
user Nginx; worker_processes auto; pid /run/Nginx.pid; ... ... events { # events context worker_connections 768; multi_accept on; ... ... } http { sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; ... ... }
user Nginx; worker_processes auto; pid /run/Nginx.pid; ... ... events { # events context worker_connections 768; multi_accept on; ... ... } http { sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; ... ... server { listen 80; server_name domain1.com; root /var/www/html/wordpress; ... } server { listen 80; server_name domain2.com; root /var/www/html/drupal; ... } }
http { ... ... server { listen 80; server_name domain1.com; root /var/www/html/wordpress; ... location /some_url { # configuration for processing URIs starting with /some_url } location /another_url { # configuration for processing URIs starting with /another_url } } server { listen 80; server_name domain2.com; root /var/www/html/drupal; ... location /some_url { # configuration for processing URIs starting with /some_url } location /some_other_url { # configuration for processing URIs starting with /some_other_url } } }
http{ ... ... upstream backend_servers { server host1.example.com; server host2.example.com; server host3.example.com; } server { listen 80; server_name example.com; location / { proxy_pass http://backend_servers; } } }
# main context mail { server_name mail.example.com; auth_http localhost:9000/cgi-bin/Nginxauth.cgi; proxy_pass_error_message on; ... } http { } ... ...
http { server { location /some_url { if (test_condition) { # do some stuff here } } } }
... ... location /wp-admin/ { limit_except GET { allow 127.0.0.1; deny all; } } ... ...
split_clients: split_client 上下文将客户端的请求分成两个或多个类别。该上下文定义在 HTTP 上下文中,主要用于 A/B 测试。
geo: 地理上下文对客户端 IP 地址进行分类。它用于根据连接的 IP 地址映射变量的值。
charset_map: 此上下文用于将特定字符集添加到"Content-Type"响应标头字段。此外,使用上下文,可以使用一些 lim 将数据从一个字符集转换为另一个字符集
map: map 上下文用于创建变量,其值取决于其他变量的值,并在 http 上下文中定义。
perl/perl_set: 用于在 Perl 中实现位置和变量处理程序,并将 Perl 调用插入 SSI。此外,借助 perl_set 上下文,我们可以为特定变量安装 Perl 处理程序。
类型: 类型上下文映射具有正确文件扩展名的 MIME 类型。此上下文可能出现在 http 上下文、服务器上下文或位置上下文中。