我需要将现有网站移动到另一台服务器。我有问题。这是原始的(工作)nginx配置:
# Define a default server, to catch requests directly to the servers IP or other non-valid sources/domains/etc.
server {
listen 80 default_server;
return 444;
}
# main.domain1 (everything defaults to this subdomain, it's a domain hack)
server {
listen 80;
listen 443 ssl;
server_name main.domain1.com;
ssl_certificate /etc/nginx/ssl/main.domain1.com.bundle.crt;
ssl_certificate_key /etc/nginx/ssl/main.domain1.com.key;
root /www/main.domain1.com;
index index.php index.html index.htm;
location /blog {
try_files $uri /?p=blog&$args;
}
location /contact {
try_files $uri /?p=contact&$args;
}
location /pics {
autoindex on;
}
location ~ /\. {
return 444;
}
location ~ \.php$ {
#try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
#fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
}
# no sub-domain or one of the other TLD's should direct to main.domain1.com
server {
listen 80;
listen 443 ssl;
server_name domain1.com .domain1.net .domain1.org;
return 301 $scheme://main.domain1.com$request_uri;
}
# domain2.com (note: this is just a testing domain for main.domain1 without the subdomain)
server {
listen 80;
server_name domain2.com;
root /www/domain2.com;
index index.php index.html index.htm;
location /blog {
try_files $uri /?p=blog&$args;
}
location /contact {
try_files $uri /?p=contact&$args;
}
location /pics {
autoindex on;
}
location ~ /\. {
return 444;
}
location ~ \.php$ {
#try_files $uri =404;
fastcgi_split_path_info ^(.+?\.php)(/.+)$;
#fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
auth_basic "Restricted";
auth_basic_user_file /www/domain2.com/.htpasswd;
}
}
# domain3.com
server {
listen 80;
server_name domain3.com;
root /www/domain3.com;
index index.php index.html index.htm;
location ~ /\. {
return 444;
}
location ~ \.php$ {
#try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
#fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
}
# catches https traffic to these other domains and sends them to non-https
# user will see ssl warning from a.ntivir.us before being redirected however
# this is not ideal, but about all we can do I think
server {
listen 443 ssl;
server_name domain2.com domain3.com;
return 301 http://$host;
}
我的第一个尝试是简单地复制domain3的服务器块,并将其替换为domain4.com。尝试重新启动/重新加载nginx时出现此错误:
nginx:[emerg]无法构建server_names_hash,你应该增加server_names_hash_bucket_size:32
因此,我将所有服务器块包装在http {}指令中,并在http级别定义server_names_hash_bucket_size 64,并且nginx仍然无法加载,说这里不允许使用http指令。从nginx文档中,它说它需要是所有服务器块的父级,所以我不明白我需要增加大小。
答案 0 :(得分:2)
我想你在/etc/nginx/nginx.conf中已经有了http {}部分(对于debian / ubuntu)而且不需要创建另一个(包装器)。
尝试在那里放置哈希命令(server_names_hash_max_size或server_names_hash_bucket_size)。