Nginx:使用

Nginx 常用的三大场景:

提供静态内容(Serving Static Content)

nginx 作为 web 服务器提供静态文件,诸如图片或者 html 等文件。例如下面的配置:

location /images/ {
    root /data;
}

例如以 /images/ 开头的请求将会被拦截,例如:http://localhost:80/images/example.png,那么对应于磁盘上的文件则是 /data/images/example.png。

作为简单代理服务器(Setting Up a Simple Proxy Server)

nginx 的一个常见用途是将其设置为代理服务器,这意味着服务器接收请求,将它们传递给处理数据的服务器,获取响应,然后将它们返回给客户端。

location /platform {
    proxy_pass http://localhost:8080;
}

例如上面的配置,访问 http://localhost:80/platform 时,请求其实是传递给了 http://localhost:8080 对应的应用处理了。

设置 FastCGI 代理(Setting Up FastCGI Proxying)

nginx 可用于将请求路由到FastCGI服务器,这些服务器运行使用各种框架和编程语言构建的应用程序。例如 php 或者 python 之类的。

location / {
    fastcgi_pass  localhost:9000;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param QUERY_STRING    $query_string;
}

参考上面的配置信息。

参考:

http://nginx.org/en/docs/beginners_guide.html

原文地址:https://www.cnblogs.com/colin220/p/11533650.html