From f604fb31bb432d3b62379c9442001043ea5a15d3 Mon Sep 17 00:00:00 2001 From: Koji Tanaka Date: Sat, 15 Apr 2017 03:59:09 +0900 Subject: [PATCH 1/2] improve url rewrite by nginx --- en/installation.rst | 60 +++++++++++++++------------------------------ 1 file changed, 20 insertions(+), 40 deletions(-) diff --git a/en/installation.rst b/en/installation.rst index cfe53f27ec..00f9eb777e 100644 --- a/en/installation.rst +++ b/en/installation.rst @@ -448,22 +448,32 @@ nginx does not make use of .htaccess files like Apache, so it is necessary to create those rewritten URLs in the site-available configuration. This is usually found in ``/etc/nginx/sites-available/your_virtual_host_conf_file``. Depending on your setup, you will have to modify this, but at the very least, you will -need PHP running as a FastCGI instance: +need PHP running as a FastCGI instance. +The following configuration redirects the request to ``webroot/index.php``: + +.. code-block:: nginx + + location / { + try_files $uri $uri/ /index.php?$args; + } + +A sample of the server directive is as follows: .. code-block:: nginx server { listen 80; + listen [::]:80; server_name www.example.com; - rewrite ^(.*) http://example.com$1 permanent; + return 301 http://example.com$request_uri; } server { listen 80; + listen [::]:80; server_name example.com; - # root directive should be global - root /var/www/example.com/public/webroot/; + root /var/www/example.com/public/webroot; index index.php; access_log /var/www/example.com/log/access.log; @@ -475,48 +485,18 @@ need PHP running as a FastCGI instance: location ~ \.php$ { try_files $uri =404; - include /etc/nginx/fastcgi_params; - fastcgi_pass 127.0.0.1:9000; - fastcgi_index index.php; - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - } - } - -On some servers (Like Ubuntu 14.04) the above configuration won't work out of -the box, and the nginx docs recommend a different approach anyway -(http://nginx.org/en/docs/http/converting_rewrite_rules.html). You might try the -following (you'll notice this is also just one server {} block, rather than two, -although if you want example.com to resolve to your CakePHP application in -addition to www.example.com consult the nginx link above): + include fastcgi_params; -.. code-block:: nginx + fastcgi_pass 127.0.0.1:9000; + # When using PHP-FPM, configure it as follows instead + # fastcgi_pass unix:/var/run/php/php7.1-fpm.sock; - server { - listen 80; - server_name www.example.com; - rewrite 301 http://www.example.com$request_uri permanent; - - # root directive should be global - root /var/www/example.com/public/webroot/; - index index.php; - - access_log /var/www/example.com/log/access.log; - error_log /var/www/example.com/log/error.log; - - location / { - try_files $uri /index.php?$args; - } - - location ~ \.php$ { - try_files $uri =404; - include /etc/nginx/fastcgi_params; - fastcgi_pass 127.0.0.1:9000; - fastcgi_index index.php; + fastcgi_index index.php; + fastcgi_intercept_errors on; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } } - IIS7 (Windows hosts) -------------------- From 92de7b36fb763609d0840e48761add6c3a833b52 Mon Sep 17 00:00:00 2001 From: Koji Tanaka Date: Sat, 15 Apr 2017 04:37:29 +0900 Subject: [PATCH 2/2] PHP-FPM configuration moved to note. (porting #3514) --- en/installation.rst | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/en/installation.rst b/en/installation.rst index 00f9eb777e..6b4225d7fe 100644 --- a/en/installation.rst +++ b/en/installation.rst @@ -486,17 +486,16 @@ A sample of the server directive is as follows: location ~ \.php$ { try_files $uri =404; include fastcgi_params; - fastcgi_pass 127.0.0.1:9000; - # When using PHP-FPM, configure it as follows instead - # fastcgi_pass unix:/var/run/php/php7.1-fpm.sock; - fastcgi_index index.php; fastcgi_intercept_errors on; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } } +.. note:: + Recent configuration of PHP-FPM is set to listen to php-fpm socket instead of TCP port 9000 on address 127.0.0.1. If you get 502 bad gateway error from above configuration, try replacing fastcgi_pass from TCP port to socket path (eg: fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;). + IIS7 (Windows hosts) --------------------