【发布时间】:2014-08-26 18:42:26
【问题描述】:
我需要将现有站点移动到另一台服务器。我有问题。这是原始(工作)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 文档中,它说它需要成为所有服务器块的父级,所以我不明白我需要在哪里增加大小。
【问题讨论】:
标签: nginx