NGINX 301(www到非www)在Ubuntu 12.04 x32数字海洋水滴上的标准化/规范化
我有一个小的数字海洋VPS水滴,安装了Ubuntu服务器12.04 x32,按照数字海洋指南安装了LEMP堆栈 我似乎无法使主机名标准化(希望将www转换为非www) 以下是来自/etc/nginx/sites enabled/default(与/sites available/default相同)的我的服务器块: (我已经用example.com替换了我的域名) 这是我的nginx.conf:NGINX 301(www到非www)在Ubuntu 12.04 x32数字海洋水滴上的标准化/规范化,nginx,http-status-code-301,digital-ocean,Nginx,Http Status Code 301,Digital Ocean,我有一个小的数字海洋VPS水滴,安装了Ubuntu服务器12.04 x32,按照数字海洋指南安装了LEMP堆栈 我似乎无法使主机名标准化(希望将www转换为非www) 以下是来自/etc/nginx/sites enabled/default(与/sites available/default相同)的我的服务器块: (我已经用example.com替换了我的域名) 这是我的nginx.conf: user www-data; worker_processes 4; pid /var/run/ng
user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
server_names_hash_bucket_size 64;
server_name_in_redirect on;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# 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 application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##
#include /etc/nginx/naxsi_core.rules;
##
# nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
##
#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
用一个可靠的答案来看看下面的问题。我想我已经正确地编写了重定向的行,我想更多的是关于我的服务器配置澄清:现在发生的是my domain.com将加载“Welcome to nginx!”页面,但不会加载www.domain.comsolved,将来如果有人有此问题,似乎您的www.hostname正在解析,如果没有,DNS不会像我的一样设置(www的cname记录指向@)
user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
server_names_hash_bucket_size 64;
server_name_in_redirect on;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# 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 application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##
#include /etc/nginx/naxsi_core.rules;
##
# nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
##
#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}