我正在尝试在运行 CentOS 7 和 nginx 的 VPS 上启用我的 drupal 网站上的 AMP 页面。以前的 Web 服务器是 Apache,由于日常请求量大,我将其更改为 Nginx 以获得更好的性能。在切换到 Nginx 之前,amp 页面结构为:domain.com/content/slug/?amp
切换到 Nginx 后,上面的链接不起作用并给出 404 但是,当我使用&
domain.com/content/slug/时它可以工作&
。我怎样才能让 nginx 接受参数并且?amp
不给出 404 错误?
这是我的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
我找到了问题。它是:
location / {
try_files $uri $uri/ /index.php?q=$request_uri;
}
所以我删除了它并添加了
location / {
# try_files $uri @rewrite; # For Drupal <= 6
try_files $uri /index.php?$query_string; # For Drupal >= 7}
希望它能帮助解决我的问题的人。