惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
S
SegmentFault 最新的问题
Jina AI
Jina AI
D
DataBreaches.Net
人人都是产品经理
人人都是产品经理
罗磊的独立博客
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
爱范儿
爱范儿
大猫的无限游戏
大猫的无限游戏
C
Check Point Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
WordPress大学
WordPress大学
博客园 - 三生石上(FineUI控件)
B
Blog
博客园 - 【当耐特】
博客园 - Franky
M
MIT News - Artificial intelligence
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
L
LangChain Blog
MyScale Blog
MyScale Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 叶小钗
Last Week in AI
Last Week in AI
Engineering at Meta
Engineering at Meta

博客园 - 逝者如斯(乎)

Redis和Memcached的区别详解 分布式系统原理与范型 - 电子支付系统 CSS3 (1) - Beginner Shell Script (2) - global.sh Python (1) - 7 Steps to Mastering Machine Learning With Python Java面试题(1)- 高级特性 Master Nginx(8) - Troubleshooting Techniques Master Nginx(7) - Nginx for the Developer Master Nginx(6) - The Nginx HTTP Server Hadoop实战课程 Java EE (14) -- SSH配置 Self-Paced Training (3) - Docker Operations Self-Paced Training (2) - Docker Fundamentals Self-Paced Training (1) - Introduction to Docker Shell Script Tutorials (0 ~ 62) Master Nginx(5) - Reverse Proxy Advanced Topics Master Nginx(4) - Nginx as a Reverse Proxy Master Nginx(3) - Using the Mail Module Master Nginx(1) - Installing Nginx and Third-Party Modules
Mater Nginx(2) - A Configuration Guide
逝者如斯(乎) · 2016-02-01 · via 博客园 - 逝者如斯(乎)

由一个主配置文件和一些辅助配置文件构成,位于conf目录下

配置指令 指令参数(配置指令对应的值)

token串分为简单字符串或复合配置块({})

简单配置项 复杂配置项

error_page 500 502 /50x.html;

location / {
root /home/html;
index index.html index.htm
}

根据逻辑意义分成了多个作用域,即配置指令上下文

nginx支持的指令上下文,即作用域

main

http

server

location

mail

指令上下文,可能有包含的情况出现。例如,通常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;
        }
    }
}