我们将上周五的一个网站迁移到运行nginx 1.10.3 + ngx_pagespeed的新服务器1.11.33.4:
Nginx配置了两个主机:
PHPMyAdmin - pma.mydomainname.com
server {
listen 80;
server_name pma.MYDOMAINNAME.com;
root /usr/share/phpmyadmin/;
index index.php;
# set expiration of assets to MAX for caching
location ~* \.(ico|css|js)(\?[0-9]+)?$ {
expires max;
log_not_found off;
}
location ~* \.php$ {
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
网站本身 - www.MYDOMAINNAME.com
server {
listen 80;
server_name MYDOMAINNAME.com www.MYDOMAINNAME;
return 301 https://www.MYDOMAINNAME.com$request_uri;
}
server {
listen 443 ssl http2;
server_name www.MYDOMAINNAME.com;
ssl on;
ssl_certificate /etc/nginx/ssl/certificate.ca-bundle;
ssl_certificate_key /etc/nginx/ssl/certificate.key;
ssl_prefer_server_ciphers on;
ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_dhparam /etc/nginx/ssl/dhparam.pem;
ssl_session_cache shared:SSL:5m;
ssl_session_timeout 1h;
error_log /var/log/nginx/DOMAIN_error.log debug;
access_log /var/log/nginx/DOMAIN_access.log;
root /var/www/www.MYDOMAINNAME.com/web;
client_max_body_size 25M;
######################################################################
################################ PAGE SPEEEED ########################
######################################################################
pagespeed on;
pagespeed FileCachePath /var/cache/pagespeed;
pagespeed Domain https://www.MYDOMAINNAME.com;
pagespeed Domain https://CDN.MYDOMAINNAME.com;
pagespeed SupportNoScriptEnabled false;
pagespeed EnableFilters combine_css;
pagespeed EnableFilters combine_javascript;
pagespeed EnableFilters prioritize_critical_css;
pagespeed EnableFilters extend_cache;
pagespeed EnableFilters make_google_analytics_async;
pagespeed EnableFilters collapse_whitespace;
pagespeed XHeaderValue "CUSTOM HEADER";
# Ensure requests for pagespeed optimized resources go to the pagespeed handler
# and no extraneous headers get set.
location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
add_header "" "";
}
location ~ "^/pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }
######################################################################
################################ STATIC FILES ########################
######################################################################
add_header Strict-Transport-Security "max-age=15768000; includeSubDomains" always;
location / {
try_files $uri /app.php$is_args$args;
}
location ~* \.(jpg|jpeg|png|gif|ico|css|js|eot|ttf|woff|woff2|svg)$ {
add_header Access-Control-Allow-Origin *;
expires 365d;
try_files $uri /app.php$is_args$args;
}
######################################################################
################################ SYMFONY #############################
######################################################################
location ~ ^/(app_dev|config)\.php(/|$) {
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}
location ~ ^/app\.php(/|$) {
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
internal;
}
location ~ \.php$ {
rewrite (.*) /app.php/not-found;
}
}
因为我们在周末看到了30%的流量下降,所以我查看了日志,我看到了一些奇怪的消息:
2017/04/03 06:24:47 [error] 6667#6667: *1093138 open() "/usr/share/phpmyadmin/FULL-REQUEST-PATH-HERE" failed (2: No such file or directory), client: <IP>, server: pma.MYDOMAINMANE.com, request: "GET /FULL-REQUEST-PATH-HERE HTTP/1.1", host: "www.MYDOMAINNAME.com"
它基本上将请求路由到www.MYDOMAINNAME.com到pma.MYDOMAINNAME.com但请求标头中的主机名实际上是www.MYDOMAINNAME.com