<p>It's a bit hard to tell from here, but have you tried putting this in your <code>general.php</code>?</p>

<pre><code>'usePathInfo' =&gt; true,
'omitScriptNameInUrls' =&gt; true,
</code></pre>

<p>...and see how you go?</p>

CC BY-SA 4.0
2018-11-01T08:55:20.857Z
I have - no effect :(

I'm pretty sure this worked with php7.1 but I'll go away and confirm/deny that before making outrageous claims.
mijewe
CC BY-SA 4.0
2018-11-01T09:08:13.000Z
Ok still doesn't work with 7.1. Have you got this config working with a C3 site?
mijewe
CC BY-SA 4.0
2018-11-01T13:18:39.423Z
Yes, I am using this exact technique on PHP 7.0, 7.1, and 7.2
andrew.welch
CC BY-SA 4.0
2018-11-01T13:19:16.263Z
Make sure you clear your FastCGI Cache by restarting php-fpm after you apply the above `general.php` settings.
andrew.welch
CC BY-SA 4.0
2018-11-01T15:46:03.163Z
No luck with that either... This is a right head scratcher. Was thinking maybe C3 does something different with admin requests so `fastcgi_param SCRIPT_FILENAME $document_root/index.php;` was screwing it up, but that doesn't seem to be it either.
mijewe
CC BY-SA 4.0
2018-11-22T16:46:04.470Z
This exact config works with Craft 2, which makes we think C3 is doing something different with admin requests. Going to /index.php?p=admin works fine, just not going to /admin.
mijewe
CC BY-SA 4.0
2018-10-31T17:18:53.553Z
2018-10-31T17:18:53.553Z
andrew.welch
<p>Right so my nginx config is a trimmed down version of Andrew Welch's config as detailed <a href="https://nystudio107.com/blog/static-caching-with-craft-cms" rel="nofollow noreferrer">here</a>.</p>

<p>All good. Caching works a dream on all the public pages.</p>

<p>However now when I go to /admin, it loads the content for the homepage, and all URLs become relative to site.com/admin.</p>

<p>I can go to /admin/login, but logging in doesn't actually work - it just redirects me to /admin/login again with no error message.</p>

<pre><code>fastcgi_cache_path /home/forge/{sitename}/cache levels=1:2 keys_zone=stagecache:100m inactive=1d use_temp_path=off max_size=100m;

# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/{sitename}/before/*;

server {
  listen 80;
  listen [::]:80;
  server_name {server};
  root /home/forge/{sitename}/web;

  # FORGE SSL (DO NOT REMOVE!)
  # ssl_certificate;
  # ssl_certificate_key;

  ssl_protocols TLSv1.2;
  ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;
  ssl_prefer_server_ciphers on;
  ssl_dhparam /etc/nginx/dhparams.pem;

  add_header X-Frame-Options "SAMEORIGIN";
  add_header X-XSS-Protection "1; mode=block";
  add_header X-Content-Type-Options "nosniff";

  index index.html index.htm index.php;
  charset utf-8;
  ssi on;

  client_max_body_size 8M;

  # 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/|cpresources/)")
  {
    set $no_cache 1;
  }

  # Change // -&gt; / for all URLs, so it works for our php location block, too
  merge_slashes off;
  rewrite (.*)//+(.*) $1/$2 permanent;

  # Access and error logging
  access_log off;
  error_log /var/log/nginx/{sitename}-error.log error;

  # FORGE CONFIG (DOT NOT REMOVE!)
  include forge-conf/{sitename}/server/*;

  # Load configuration files from nginx-partials
  include /etc/nginx/nginx-partials/*.conf;

  # Root directory location handler
  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;
  }

  # 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.2-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;

    # 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 stagecache;
    fastcgi_hide_header Set-Cookie;
    fastcgi_cache_valid 200 1d;
    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.2-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root/index.php;
    fastcgi_param PATH_INFO $query_string;

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

# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/{sitename}/after/*;
</code></pre>

<p>by looking at the headers it doesn't seem that /admin is being cached or anything, and I send a test header in the <code>@phpfpm_nocache</code> block to prove that it's going to the right place, which makes me think it's a problem with the <code>@phpfpm_nocache</code> block. And that's where I am now.</p>

<p>So... what's going on?</p>

<p>Cheers!</p>

<craft3><admin><nginx>
/admin displays homepage content, and I can't login
# /admin displays homepage content, and I can't login

(Asked by: username_0 on 2018-10-31)

Right so my nginx config is a trimmed down version of Andrew Welch's config as detailed here.
All good. Caching works a dream on all the public pages.
However now when I go to /admin, it loads the content for the homepage, and all URLs become relative to site.com/admin.
I can go to /admin/login, but logging in doesn't actually work - it just redirects me to /admin/login again with no error message.
fastcgi_cache_path /home/forge/{sitename}/cache levels=1:2 keys_zone=stagecache:100m inactive=1d use_temp_path=off max_size=100m;

# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/{sitename}/before/*;

server {
  listen 80;
  listen [::]:80;
  server_name {server};
  root /home/forge/{sitename}/web;

  # FORGE SSL (DO NOT REMOVE!)
  # ssl_certificate;
  # ssl_certificate_key;

  ssl_protocols TLSv1.2;
  ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;
  ssl_prefer_server_ciphers on;
  ssl_dhparam /etc/nginx/dhparams.pem;

  add_header X-Frame-Options "SAMEORIGIN";
  add_header X-XSS-Protection "1; mode=block";
  add_header X-Content-Type-Options "nosniff";

  index index.html index.htm index.php;
  charset utf-8;
  ssi on;

  client_max_body_size 8M;

  # 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/|cpresources/)")
  {
    set $no_cache 1;
  }

  # Change // -> / for all URLs, so it works for our php location block, too
  merge_slashes off;
  rewrite (.*)//+(.*) $1/$2 permanent;

  # Access and error logging
  access_log off;
  error_log /var/log/nginx/{sitename}-error.log error;

  # FORGE CONFIG (DOT NOT REMOVE!)
  include forge-conf/{sitename}/server/*;

  # Load configuration files from nginx-partials
  include /etc/nginx/nginx-partials/*.conf;

  # Root directory location handler
  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;
  }

  # 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.2-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;

    # 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 stagecache;
    fastcgi_hide_header Set-Cookie;
    fastcgi_cache_valid 200 1d;
    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.2-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root/index.php;
    fastcgi_param PATH_INFO $query_string;

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

# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/{sitename}/after/*;

by looking at the headers it doesn't seem that /admin is being cached or anything, and I send a test header in the @phpfpm_nocache block to prove that it's going to the right place, which makes me think it's a problem with the @phpfpm_nocache block. And that's where I am now.
So... what's going on?
Cheers!

**Tags:** craft3, admin, nginx

---

## 1 answers

### Answer by username_1 on 2018-10-31. Score: 1

It's a bit hard to tell from here, but have you tried putting this in your general.php?
'usePathInfo' => true,
'omitScriptNameInUrls' => true,

...and see how you go?

> **Comments:**
> **username_0**: I have - no effect :(  I'm pretty sure this worked with php7.1 but I'll go away and confirm/deny that before making outrageous claims.  
> **username_0**: Ok still doesn't work with 7.1. Have you got this config working with a C3 site?  
> **username_1**: Yes, I am using this exact technique on PHP 7.0, 7.1, and 7.2  
> **username_1**: Make sure you clear your FastCGI Cache by restarting php-fpm after you apply the above `general.php` settings.  
> **username_0**: No luck with that either... This is a right head scratcher. Was thinking maybe C3 does something different with admin requests so `fastcgi_param SCRIPT_FILENAME $document_root/index.php;` was screwing it up, but that doesn't seem to be it either.  
> **username_0**: This exact config works with Craft 2, which makes we think C3 is doing something different with admin requests. Going to /index.php?p=admin works fine, just not going to /admin.  

---

