尝试使用www和非www域重定向时,我无法找到规范化错误的来源,如:
server {
listen 80;
server_name www.aws.mikeg.de;
rewrite ^/(.*) http://aws.mikeg.de/$1 permanent;
return 301 http://aws.mikeg.de$request_uri;
}
我检查了两次文件权限的所有文件夹。我感到困惑的是,重定向到www.Subdomain的工作方式是有效的,而反向重定向到非www则不然。这是我的完整nginx配置:
user www-data www-data;
worker_processes 1;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
include fastcgi.conf;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
log_format cache '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" nocache:$skip_cache '
'$upstream_cache_status';
access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log;
sendfile on;
keepalive_timeout 65;
tcp_nodelay on;
server_names_hash_bucket_size 128;
# Use gzip compression
# gzip_static on; # Uncomment if you compiled Nginx using --with-http_gzip_static_module
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css text/javascript text/xml application/json application/x-javascript application/xml application/xm$ application/xml+rss image/png image/gif image/jpeg;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
# Fast-CGI cache
fastcgi_cache_path /var/cache/nginx/wordpress levels=1:2 keys_zone=WORDPRESS:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_cache_use_stale error timeout invalid_header http_500;
add_header X-Cache $upstream_cache_status;
server {
listen 80;
server_name www.aws.mikeg.de;
#rewrite ^/(.*) http://aws.mikeg.de/$1 permanent;
return 301 http://aws.mikeg.de$request_uri;
}
server {
listen 80 default_server;
server_name aws.mikeg.de 54.194.222.209;
root /srv/wordpress/;
index index.php;
# Turned off since W3 Total Cache will handle caching
# and mod_pagespeed won't enhance WP: http://wordpress.org/support/topic/plugin-w3-total-cache-googles-mod_pagespeed-and-w3
pagespeed Off;
# Include nginx.conf made by W3 Total Cache
include /srv/wordpress/nginx.conf;
access_log /var/log/nginx/wordpress.log cache;
error_log /var/log/nginx/wordpress.error.log;
rewrite_log on;
# Set a variable to work around the lack of nested conditionals
set $cache_uri $request_uri;
set $skip_cache 0;
if ($query_string != "") {
set $skip_cache 1;
}
# Don't cache uris containing the following segments
if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml|\/wp-(app|cron|login|register|mail)\.php|wp\-comments\-popup\.php|wp\-links\-opml\.php|wp\-locations\.php") {
set $skip_cache 1;
}
# Don't use the cache for logged in users or recent commenters
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
set $skip_cache 1;
}
location ~ /purge(/.*) {
fastcgi_cache_purge WORDPRESS "$scheme$request_method$host$1";
}
location / {
# Use cached or actual file if they exists, otherwise pass request to WordPress
#try_files $uri $uri/ /index.php?q=$uri&$args;
try_files $uri $uri/ /index.php?q=$request_uri;
# SECURITY
if ($request_method !~ ^(GET|HEAD|POST)$ ) {
return 444;
}
# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {
set $skip_cache 1;
}
# this serves static files that exist without running other rewrite tests
if (-f $request_filename) {
expires 30d; break;
}
}
location ~ \.php$ {
fastcgi_cache WORDPRESS;
fastcgi_cache_valid 200 60m;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
# Note: fastcgi_index is not needed is standard PHP location ~ \.php$ is useed: http://blog.martinfjordvald.com/2011/01/no-input-file-specified-with-php-and-nginx/
}
# Rewrites fpr category base
# SECURITY
# Deny access to hidden files
location ~* /\. {
deny all;
access_log off;
log_not_found off;
}
# Deny access to any files with a .php extension in the uploads directory
location ~* /(?:uploads|files)/.*\.php$ {
deny all;
}
# Deny access to system files in root
location ~ /(\.|wp-config.php|liesmich.html|readme.html) {
return 444;
}
# Allow access to favicon and robots.txt
location = /(favicon\.ico|robots\.txt) {
allow all;
log_not_found off;
access_log off;
}
# Only recommended when wordpress comments are disabled
#location ~ /(\.|wp-config.php|liesmich.html|readme.html|xmlrpc.php|wp-comments-post.php) {
#return 444
#}
}
}
编辑:知道了......我的提供商弄乱了eDNS设置。 nginx配置很好用。
答案 0 :(得分:0)
使用此作为默认服务器块来捕获和拒绝未明确定义的位置的所有流量。
server {
listen 80 default_server;
server_name _;
deny all;
}