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/&
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;
}