Nginx系列(二)-配置文件
上一篇: Nginx系列(一)-部署
一、 配置结构划分
1. 下面是默认配置文件移除注释之后的样子.
2. 最外层就是 ·全局· 域,用来配置一些全局参数. ex: worker_processes
3. 然后就是events模块域: 用来配置工作方式
4. 然后和events平级的http模块域:
5. http模块域内部有http全局域和server域
6. server域中有server全局域和location域
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
二、 相关配置参数
user nginx;
worker_processes 1;
pid logs/nginx.pid;
events {
use epoll;
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
sendfile on;
keepalive_timeout 65;
gzip on;
upstream nginxtest{
server 127.0.0.1:8081;
server 127.0.0.1:8082;
}
upstream nginxtest{
server 127.0.0.1:8081 weight=1;
server 127.0.0.1:8082 weight=3;
}
upstream nginxtest{
ip_hash;
server 127.0.0.1:8081 weight=1;
server 127.0.0.1:8082 weight=3;
}
upstream nginxtest{
least_conn;
server 127.0.0.1:8081 weight=1;
server 127.0.0.1:8082 weight=3;
}
limit_req_zone $binary_remote_addr zone=nginxtest:10m rate=1r/s;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
location ~*\.(gif|jpg|png|jepg|bmp)$ {
expires 3d;
proxy_set_header Accept-Encoding '';
root /home/mpeg/nginx
proxy_store on;
proxy_store_access user:rw group:rw all:rw;
proxy_temp_path /home/mpeg/nginx;
if(!-e $request_filename){
proxy_pass http://127.0.0.1:8081
}
}
location /test {
proxy_pass http://nginxtest;
limit_req zone=nginxtest burst=5 nodelay;
limit_req_status 598;
index index.html index.htm;
root html;
}
location ~* \.(jpg|gif|png)${ # 动静分离
proxy_pass http://127.0.0.1:8083;#代理转发
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
三、 总结
本文是博主笔记篇.没有很仔细的介绍相关配置.
|