<p>Try adding specific location for admin &amp; cpresources in the nginx config</p>

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

<p>before</p>

<pre><code>location ~ [^/]\.php(/|$) {
</code></pre>

CC BY-SA 3.0
2018-02-19T18:29:49.010Z
2018-02-19T18:29:49.010Z
a-am
<p>I am trying to configure NGINX to serve a craft 2 site.  I am getting the requests being routed through <code>index.php</code> for template url's but not for any admin routes which are redirecting to <code>index.php?p=/admin/**/*</code>. </p>

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

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

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

<p>here is my nginx config:  </p>

<pre><code>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;
}
</code></pre>

<p>Update:</p>

<p>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?</p>

<routing>
Nginx config for craft working for everything but admin url's
# Nginx config for craft working for everything but admin url's

(Asked by: username_0 on 2018-02-19)

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?

**Tags:** routing


---

## 1 answers

### Answer by username_1 on 2018-02-19. Score: 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(/|$) {


---

