由一个主配置文件和一些辅助配置文件构成,位于conf目录下
配置指令 指令参数(配置指令对应的值)
token串分为简单字符串或复合配置块({})
简单配置项 复杂配置项
error_page 500 502 /50x.html;
location / {
root /home/html;
index index.html index.htm
}
根据逻辑意义分成了多个作用域,即配置指令上下文
nginx支持的指令上下文,即作用域
main
http
server
location
指令上下文,可能有包含的情况出现。例如,通常http上下文和mail上下文一定是出现在main上下文里。
user nobody;
worker_processes 1;
error_log logs/error.log info;
events {
worker_connections 1024;
}
http {
server {
listen 80;
server_name www.linuxdc.com;
}
}
The basic configuration format
Nginx global configuration parameters
Using include files
The HTTP server section
The virtual server section
Locations - where, when and how
The mail server section
Full sample configuration
Loadbalance
upstream web_backend { server 10.11.12.51 server 10.11.12.52 } server { listen 80; location / { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://web_backend; } }
///////////////////////////////////////////////////////////////////////////////////////////////////////
Starting, Stopping, and Reloading Configuration
nginx -s stop --fast shutdown nginx -s quit --graceful shutdown nginx -s reload --reloading the config file nginx -s reopen --reopening the log files kill -s QUIT 1628 ps -ax | grep nginx
Serving Static Content
/data/www --index.html
/data/images --some images
http {
server {
location / {
root /data/www;
}
location /images/ {
root /data;
}
}
}
http://localhost/images/example.png -- /data/images/example.png
http://localhost/some/example.html -- /data/www/some/example.html
nginx -s reload
Find out reason in access.log or error.log, in the directory of /usr/local/nginx/logs or /var/log/nginx
Setting Up a Simple Proxy Server
http {
server {
location / {
proxy_pass http://localhost:8080;
}
location ~ .(gif|jpg|png)$ {
root /data/images;
}
}
}
Setting Up FastCGI Proxying
http {
server {
location / {
fastcgi_pass localhost:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
}
location ~ .(gif|jpg|png)$ {
root /data/images;
}
}
}