4、nginx设置FastCGI代理-阅读官方文档

官网:Beginner’s Guide

翻译部分:Setting Up FastCGI Proxying

tips: FastCGI是一个协议

开始!


nginx can be used to route requests to FastCGI servers which run applications built with various frameworks and programming languages such as PHP.

 nginx可以用来路由请求到用各种各样的框架和编程语言建立的FastCGI服务器上。


The most basic nginx configuration to work with a FastCGI server includes using the fastcgi_pass directive instead of the proxy_pass directive, and  fastcgi_param directives to set parameters passed to a FastCGI server.

 能够和FastCGI服务器工作最基本的nginx配置包括fastcgi_pass,fastcgi_param指令。

fastcgi_param设置传个FastCGI服务器的参数。


Suppose the FastCGI server is accessible on localhost:9000.

 假设在localhost:9000上可以访问到FastCGI服务器。


Taking the proxy configuration from the previous section as a basis, replace the proxy_pass directive with the fastcgi_pass directive and change the parameter to localhost:9000.

将之前那些部分的demo:proxy_pass http://localhost:8080/; 修改成下面这样

 fastcgi_pass localhost:9000;


In PHP, the SCRIPT_FILENAME parameter is used for determining the script name, and the QUERY_STRING parameter is used to pass request parameters.

 在PHP中,SCRIPT_FILENAME参数用来决定脚本名称

 QUERY_STRING参数用来传递请求参数


The resulting configuration would be:

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;
    }
}

 最终配置文件长这样。


This will set up a server that will route all requests except for requests for static images to the proxied server operating on localhost:9000 through the FastCGI protocol.

 上面的配置会设置一个服务器,它会通过FastCGI协议,路由除静态文件请求以外的请求到跑在localhost:9000 上的被代理服务器。

你可能感兴趣的:(nginx,运维)