1

I'm trying to enable AMP pages on my drupal website on a VPS running on CentOS 7 and nginx. Previous web server was Apache and I changed it to Nginx for better performance due to daily requests. Before switching to Nginx, the amp page structure was: domain.com/content/slug/?amp after switching to Nginx, the link above does not work and gives 404 BUT, it works when I use &, domain.com/content/slug/&amp How can I make nginx to accept the parameter as ?amp and not give 404 errors?

Here's my nginx.conf :

server
{
    listen SERVER_IP:443 ssl http2;
    server_name example.com www.example.com ;
    access_log /var/log/nginx/domains/example.com.log;
    access_log /var/log/nginx/domains/example.com.bytes bytes;
    error_log /var/log/nginx/domains/example.com.error.log;
    root /home/user_name/domains/example.com/private_html;
    index index.php index.html index.htm;
    ssl_certificate     /etc/nginx/ssl/ssl.crt;
    ssl_certificate_key /etc/nginx/ssl/crt.key;
    if ($host = www.example.com){
        return 301 https://example.com$request_uri;
    }
    include /usr/local/directadmin/data/users/name/nginx_php.conf;
    include /etc/nginx/webapps.ssl.conf;
    
    location / {
        try_files $uri $uri/ /index.php?q=$request_uri;
    }
    
    location @rewrite {
        rewrite ^/(.*)$ /index.php?q=$1;
    }
    
    location ~ ^(/[a-z\-]+)?/system/files/ { # For Drupal >= 7
        try_files $uri /index.php?$query_string;
    }
    
    
    location ~* \.(png|jpg|jpeg|gif|ico|svg)$ {
        try_files $uri @rewrite;
        add_header Cache-Control "public, max-age=604800";
        log_not_found off;
        access_log off;
    }
    location ~* \.(js|html|css|woff|woff2|ttf|eot)$ {
        try_files $uri @rewrite;
        add_header Cache-Control "public, max-age=2592000";
        log_not_found off;
        access_log off;
    }
    client_body_buffer_size 10K;
    client_header_buffer_size 1k;
    client_max_body_size 50m;
    large_client_header_buffers 4 4k;
    client_body_timeout 12;
    client_header_timeout 12;
    keepalive_timeout 15;
    send_timeout 10;
}
1
  • What does your access.log file show is happening for these requests returning 404?
    – iangetz
    Feb 21, 2021 at 14:13

1 Answer 1

0

I found the problem. It was :

location / {
    try_files $uri $uri/ /index.php?q=$request_uri;
}

So I removed it and added

location / {
# try_files $uri @rewrite; # For Drupal <= 6
try_files $uri /index.php?$query_string; # For Drupal >= 7}

Hope it helps anyone with my problem.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .