1

I am trying to configure NGINX to serve a craft 2 site. I am getting the requests being routed through index.php for template url's but not for any admin routes which are redirecting to index.php?p=/admin/**/*.

I am assuming this has more to do with my NGINX config than craft as I have the following option enabled:

'omitScriptNameInUrls' => 'true',

Is there any craft related reason that admin URL's would redirect that way whereas template url's wouldn't?

here is my nginx config:

server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;

index index.html index.htm index.php;

server_name _;

error_log  off;
access_log off;

root /code/public;

charset utf-8;


location / {
    try_files $uri/index.html $uri $uri/ /index.php?$query_string;
}

location ~ [^/]\.php(/|$) {
    try_files $uri $uri/ /index.php?$query_string;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass php:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    include fastcgi_params;
}

# Disable reading of Apache .htaccess files
location ~ /\.ht {
    deny all;
}

# Misc settings
sendfile off;
client_max_body_size 100m;

# 404 error handler
error_page 404 /index.php?$query_string;
}

Update:

just deployed this same app to AWS elastic beanstalk and am running into the same issue with Apache. This leads me to think maybe it's not related to nginx?

9er
  • 179
  • 9

1 Answers1

1

Try adding specific location for admin & cpresources in the nginx config

location ^~ /admin {
    try_files $uri $uri/ /index.php?$query_string;
}
location ^~ /cpresources {
    try_files $uri $uri/ /index.php?$query_string;
}

before

location ~ [^/]\.php(/|$) {
a-am
  • 2,857
  • 1
  • 19
  • 25