Nginx Config

I was looking at the guide here https://github.com/yiisoft/yii2/blob/master/docs/guide/installation.md to see what the recommended nginx config is but it makes a reference to fastcgi.conf

Is there a copy of this about? Not sure if it’s Yii specific or not.

The fastcgi.conf is very system sepcific. That’s why it is not included. You should have a copy of it already through your nginx-install, though.

Ah yes, didn’t realise.

Mine is just called fastcgi_params.

Hm, that’s not necessarily the same … On CentOS, they are indeed identical.

For comparison: This is my (I think) unaltered [font="Courier New"]fastcgi_params[/font]:




fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;

fastcgi_param  QUERY_STRING       $query_string;

fastcgi_param  REQUEST_METHOD     $request_method;

fastcgi_param  CONTENT_TYPE       $content_type;

fastcgi_param  CONTENT_LENGTH     $content_length;


fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;

fastcgi_param  REQUEST_URI        $request_uri;

fastcgi_param  DOCUMENT_URI       $document_uri;

fastcgi_param  DOCUMENT_ROOT      $document_root;

fastcgi_param  SERVER_PROTOCOL    $server_protocol;


fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;

fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;


fastcgi_param  REMOTE_ADDR        $remote_addr;

fastcgi_param  REMOTE_PORT        $remote_port;

fastcgi_param  SERVER_ADDR        $server_addr;

fastcgi_param  SERVER_PORT        $server_port;

fastcgi_param  SERVER_NAME        $server_name;


# PHP only, required if PHP was built with --enable-force-cgi-redirect

fastcgi_param  REDIRECT_STATUS    200;



I’ve got it included in my [font=“Courier New”]php_params[/font]:




include		fastcgi_params;

fastcgi_index	index.php;

fastcgi_param	SCRIPT_FILENAME		$document_root$fastcgi_script_name;


// SSL detection

fastcgi_param	HTTPS			$https;

fastcgi_param	SSL_PROTOCOL		$ssl_protocol;

fastcgi_param	SSL_CIPHER		$ssl_cipher;

fastcgi_param	SSL_SESSION_ID		$ssl_session_id;

fastcgi_param	SSL_CLIENT_VERIFY	$ssl_client_verify;




// This is an optimization thing for php-fpm. Ignore or even omit it unless you know what you're doing

fastcgi_param	REQUEST_BODY_FILE	$request_body_file;

fastcgi_pass_request_body		off;

client_body_in_file_only		clean;



And finally my php.conf:




location ~ \.php$ {

    include		php_params;

    fastcgi_pass	unix:/var/run/php-fpm/php-fpm.sock;

}



Please don’t copy it verbatim, though. the socket location and type for php-fpm might differ on your system.

It’s not the same. fastcgi.conf is included in latest versions of nginx while in outdated versions it’s missing. Content should be the following:




fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;

fastcgi_param  QUERY_STRING       $query_string;

fastcgi_param  REQUEST_METHOD     $request_method;

fastcgi_param  CONTENT_TYPE       $content_type;

fastcgi_param  CONTENT_LENGTH     $content_length;


fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;

fastcgi_param  REQUEST_URI        $request_uri;

fastcgi_param  DOCUMENT_URI       $document_uri;

fastcgi_param  DOCUMENT_ROOT      $document_root;

fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  HTTPS              $https if_not_empty;


fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;

fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;


fastcgi_param  REMOTE_ADDR        $remote_addr;

fastcgi_param  REMOTE_PORT        $remote_port;

fastcgi_param  SERVER_ADDR        $server_addr;

fastcgi_param  SERVER_PORT        $server_port;

fastcgi_param  SERVER_NAME        $server_name;


# PHP only, required if PHP was built with --enable-force-cgi-redirect

fastcgi_param  REDIRECT_STATUS    200;