<p>You might also need to add something like this for your actions pages:</p>

<pre><code>location ^~ /actions/users/setpassword {
    try_files $uri $uri/ @phpfpm_nocache;
}
</code></pre>

CC BY-SA 4.0
2018-11-03T23:04:39.480Z
2018-11-03T23:04:39.480Z
Advk
<p>The issue had something to do with <strong>PATH_INFO</strong>. Adding '<strong>usePathInfo => true</strong>' in <strong>general.php</strong> fixed the issue. Here's the detailed explanation from Craft docs: <a href="https://craftcms.com/support/enable-path-info" rel="nofollow noreferrer">https://craftcms.com/support/enable-path-info</a>.</p>

CC BY-SA 3.0
2017-07-16T20:20:50.420Z
Ah glad you figured it out, thanks for sharing the answer.
andrew.welch
CC BY-SA 3.0
2017-08-05T11:12:22.043Z
@khalwat I should be the one thanking you. I love your articles. I learned a lot from them.
Anya Dit
CC BY-SA 3.0
2017-07-13T03:58:38.510Z
2017-07-13T03:58:38.510Z
Anya Dit
<p>This isn't Craft issue per se. But I was wondering if anyone can help me out. I’m trying to enable FastCGI Cache in my server. My nginx server block is coming from this helpful article: <a href="https://nystudio107.com/blog/static-caching-with-craft-cms" rel="nofollow noreferrer">https://nystudio107.com/blog/static-caching-with-craft-cms</a>.</p>

<p>The caching works because the site is now considerably faster. The issue is when I try to login in Craft's login page: <code>/admin/login</code>, it goes to <code>/admin</code> but it goes back to <code>/admin/login/</code> not to the dashboard page. </p>

<p>I have reached out to the article's author and he responded that,</p>

<blockquote>
  <p>it isn't properly <em>not</em> stripping cookies off of the admin cp requests.</p>
</blockquote>

<p>Here's my server block:</p>

<pre><code>fastcgi_cache_path /etc/nginx/cache/site levels=1:2 keys_zone=SITE:100m inactive=30m;

server {
    listen 80;
    access_log /var/log/nginx/site.access.log;
    error_log  /var/log/nginx/site.error.log;
    root /var/www/site/public;
    index index.html index.htm index.php;
    charset utf-8;
    ssi on;
    server_name site.ac;
    #404 error handler
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }
    #Cache everything by default
    fastcgi_cache_key "$scheme$request_method$host$request_uri";
    add_header X-Cache $upstream_cache_status;
    set $no_cache 0;
    if ($request_method = POST)
    {
        set $no_cache 1;
    }
    if ($request_uri ~* "/admin/|eecms/|actions/|cpresources/")
    {
        set $no_cache 1;
    }
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    # Craft-specific location handlers to ensure AdminCP requests route through index.php
    # If you change your `cpTrigger`, change it here as well
    location ^~ /admin {
        try_files $uri $uri/ @phpfpm_nocache;
    }
    location ^~ /index.php/admin {
        try_files $uri $uri/ @phpfpm_nocache;
    }
    location ^~ /cpresources {
        try_files $uri $uri/ /index.php?$query_string;
    }
    location ^~ /eecms {
        try_files $uri $uri/ @phpfpm_nocache;
    }
    location ^~ /index.php/eecms {
        try_files $uri $uri/ @phpfpm_nocache;
    }
    #php-fpm configuration
    location ~ [^/]\.php(/|$) {
        try_files $uri $uri/ /index.php?$query_string;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        # php-fpm parameters
        fastcgi_param HTTP_PROXY "";
        fastcgi_param CRAFTENV_CRAFT_ENVIRONMENT "";
        fastcgi_param CRAFTENV_DB_HOST "127.0.0.1";
        fastcgi_param CRAFTENV_DB_NAME "x";
        fastcgi_param CRAFTENV_DB_USER "x";
        fastcgi_param CRAFTENV_DB_PASS "x";
        fastcgi_param CRAFTENV_SITE_URL "http://site.ac/";
        fastcgi_param CRAFTENV_BASE_URL "http://site.ac/";
        fastcgi_param CRAFTENV_BASE_PATH "/var/www/site/public/";
        # shared php-fpm configuration
        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
        # FastCGI Cache settings
        fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
        fastcgi_cache SITE;
        fastcgi_hide_header Set-Cookie;
        fastcgi_cache_valid 200 30m;
        fastcgi_cache_use_stale updating error timeout invalid_header http_500;
        fastcgi_cache_bypass $no_cache;
        fastcgi_no_cache $no_cache;
    }
    # php-fpm configuration for non-cached content
    location @phpfpm_nocache {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root/index.php;
        fastcgi_param PATH_INFO $query_string;
        # php-fpm parameters
        fastcgi_param HTTP_PROXY "";
        fastcgi_param CRAFTENV_CRAFT_ENVIRONMENT "";
        fastcgi_param CRAFTENV_DB_HOST "127.0.0.1";
        fastcgi_param CRAFTENV_DB_NAME "x";
        fastcgi_param CRAFTENV_DB_USER "x";
        fastcgi_param CRAFTENV_DB_PASS "x";
        fastcgi_param CRAFTENV_SITE_URL "http://site.ac/";
        fastcgi_param CRAFTENV_BASE_URL "http://site.ac/";
        fastcgi_param CRAFTENV_BASE_PATH "/var/www/site/public/";
        # shared php-fpm configuration
        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
        # No FastCGI Cache
        fastcgi_cache_bypass 1;
        fastcgi_no_cache 1;
    }
    location ~ /\.ht {
        deny all;
    }
}
</code></pre>

<p>I hope someone can shed some light on this issue I'm having. Any suggestions or comments is greatly appreciated.</p>

CC BY-SA 3.0
2017-07-12T05:45:39.383Z
Is this a Craft site? What is the `eecms` page?
andrew.welch
CC BY-SA 3.0
2017-07-12T06:09:15.163Z
Yes, it's a Craft site. I changed the cpTrigger to eecms.
Anya Dit
<cache><nginx>
Static page caching using Nginx FastCGI Cache with CraftCMS
# Static page caching using Nginx FastCGI Cache with CraftCMS

(Asked by: username_0 on 2017-07-12)

This isn't Craft issue per se. But I was wondering if anyone can help me out. I’m trying to enable FastCGI Cache in my server. My nginx server block is coming from this helpful article: https://nystudio107.com/blog/static-caching-with-craft-cms.
The caching works because the site is now considerably faster. The issue is when I try to login in Craft's login page: /admin/login, it goes to /admin but it goes back to /admin/login/ not to the dashboard page. 
I have reached out to the article's author and he responded that,

it isn't properly not stripping cookies off of the admin cp requests.

Here's my server block:
fastcgi_cache_path /etc/nginx/cache/site levels=1:2 keys_zone=SITE:100m inactive=30m;

server {
    listen 80;
    access_log /var/log/nginx/site.access.log;
    error_log  /var/log/nginx/site.error.log;
    root /var/www/site/public;
    index index.html index.htm index.php;
    charset utf-8;
    ssi on;
    server_name site.ac;
    #404 error handler
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }
    #Cache everything by default
    fastcgi_cache_key "$scheme$request_method$host$request_uri";
    add_header X-Cache $upstream_cache_status;
    set $no_cache 0;
    if ($request_method = POST)
    {
        set $no_cache 1;
    }
    if ($request_uri ~* "/admin/|eecms/|actions/|cpresources/")
    {
        set $no_cache 1;
    }
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    # Craft-specific location handlers to ensure AdminCP requests route through index.php
    # If you change your `cpTrigger`, change it here as well
    location ^~ /admin {
        try_files $uri $uri/ @phpfpm_nocache;
    }
    location ^~ /index.php/admin {
        try_files $uri $uri/ @phpfpm_nocache;
    }
    location ^~ /cpresources {
        try_files $uri $uri/ /index.php?$query_string;
    }
    location ^~ /eecms {
        try_files $uri $uri/ @phpfpm_nocache;
    }
    location ^~ /index.php/eecms {
        try_files $uri $uri/ @phpfpm_nocache;
    }
    #php-fpm configuration
    location ~ [^/]\.php(/|$) {
        try_files $uri $uri/ /index.php?$query_string;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        # php-fpm parameters
        fastcgi_param HTTP_PROXY "";
        fastcgi_param CRAFTENV_CRAFT_ENVIRONMENT "";
        fastcgi_param CRAFTENV_DB_HOST "127.0.0.1";
        fastcgi_param CRAFTENV_DB_NAME "x";
        fastcgi_param CRAFTENV_DB_USER "x";
        fastcgi_param CRAFTENV_DB_PASS "x";
        fastcgi_param CRAFTENV_SITE_URL "http://site.ac/";
        fastcgi_param CRAFTENV_BASE_URL "http://site.ac/";
        fastcgi_param CRAFTENV_BASE_PATH "/var/www/site/public/";
        # shared php-fpm configuration
        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
        # FastCGI Cache settings
        fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
        fastcgi_cache SITE;
        fastcgi_hide_header Set-Cookie;
        fastcgi_cache_valid 200 30m;
        fastcgi_cache_use_stale updating error timeout invalid_header http_500;
        fastcgi_cache_bypass $no_cache;
        fastcgi_no_cache $no_cache;
    }
    # php-fpm configuration for non-cached content
    location @phpfpm_nocache {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root/index.php;
        fastcgi_param PATH_INFO $query_string;
        # php-fpm parameters
        fastcgi_param HTTP_PROXY "";
        fastcgi_param CRAFTENV_CRAFT_ENVIRONMENT "";
        fastcgi_param CRAFTENV_DB_HOST "127.0.0.1";
        fastcgi_param CRAFTENV_DB_NAME "x";
        fastcgi_param CRAFTENV_DB_USER "x";
        fastcgi_param CRAFTENV_DB_PASS "x";
        fastcgi_param CRAFTENV_SITE_URL "http://site.ac/";
        fastcgi_param CRAFTENV_BASE_URL "http://site.ac/";
        fastcgi_param CRAFTENV_BASE_PATH "/var/www/site/public/";
        # shared php-fpm configuration
        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
        # No FastCGI Cache
        fastcgi_cache_bypass 1;
        fastcgi_no_cache 1;
    }
    location ~ /\.ht {
        deny all;
    }
}

I hope someone can shed some light on this issue I'm having. Any suggestions or comments is greatly appreciated.

**Tags:** cache, nginx

> **Comments:**
> **username_1**: Is this a Craft site? What is the `eecms` page?  
> **username_0**: Yes, it's a Craft site. I changed the cpTrigger to eecms.  

---

## 2 answers

### Answer by username_0 on 2017-07-13. Score: 4 | Accepted answer

The issue had something to do with **PATH\_INFO**. Adding '**usePathInfo => true**' in **general.php** fixed the issue. Here's the detailed explanation from Craft docs: <https://craftcms.com/support/enable-path-info>.

> **Comments:**
> **username_1**: Ah glad you figured it out, thanks for sharing the answer.  
> **username_0**: @khalwat I should be the one thanking you. I love your articles. I learned a lot from them.  

---

### Answer by username_2 on 2018-11-03. Score: 1

You might also need to add something like this for your actions pages:
location ^~ /actions/users/setpassword {
    try_files $uri $uri/ @phpfpm_nocache;
}


---

