我有一个我公司用于Web服务器的虚拟机。我们上面是一个内部PHP应用程序,现在需要向该服务器添加一个站点。问题是VM上有一个IP。我将Windows DNS管理器设置为指向此IP但它只会拉起主站点。有没有办法将nginx配置到它将选择哪个站点的位置?
这是我的第一个网站配置:
server {
server_name develop.aspirion.com;
root /var/www/vhosts/develop.aspirion.com;
index index.html;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
这是我的第二个网站配置:
server {
server_name aspirion.com;
access_log /var/log/nginx/aspirion.com-access.log;
error_log /var/log/nginx/aspirion.com-error.log;
root /var/virtual/aspirion.com/master/current/webroot;
index index.php;
location / {
# error_page 404 /index.php;
location = / {
error_page 404 =200 /index.html;
}
location ~* ^.+\.(?:css|js|jpe?g|gif|htc|ico|png|html|xml)$ {
access_log off;
expires 30d;
tcp_nodelay off;
open_file_cache max=3000 inactive=120s;
open_file_cache_valid 45s;
open_file_cache_min_uses 2;
open_file_cache_errors off;
}
location ~* ^.+\.(?:pdf|pptx?)$ {
expires 30d;
tcp_nodelay off;
}
# TODO: never allow private files inside the web root?
location ^~ /sites/default/files/private/ {
internal;
}
location ~* ^(?:.+\.(?:htaccess|make|txt|engine|inc|info|install|module|profile|po|sh|.*sql|theme|tpl(?:\.php)?|xtmpl)|code-style\.pl|/Entries.*|/Repository|/Root|/Tag|/Template)$ {
return 404;
}
try_files $uri $uri/ /index.php?$uri&$args;
}
location = /index.php {
fastcgi_pass phpcgi;
}
location = /.git {
return 404;
}
location = /patches {
return 404;
}
location = /backup {
return 404;
}
location = /robots.txt {
access_log off;
}
location = /humans.txt {
access_log off;
try_files $uri $uri/ /index.php?$uri&$args;
}
location = /rss.xml {
try_files $uri $uri/ /index.php?$uri&$args;
}
location = /sitemap.xml {
try_files $uri $uri/ /index.php?$uri&$args;
}
location = /favicon.ico {
try_files /favicon.ico =204;
}
location ~* ^.+\.php$ {
return 404;
}
}
server {
server_name munin.aspirion.com;
include sites-available/admin.conf;
}
答案 0 :(得分:1)
是的,Nginx通过单个IP地址提供多个域是正常的。
浏览器将两个域的DNS解析为相同的IP,然后将流量转发到该IP地址上的端口80。 Nginx正在侦听并检查传入的Host:
标头,并将其与配置中的server_name
值进行匹配。您的问题与在一个IP地址上拥有两个域无关。试试这个:
sites-available
中,请确保有sites-enabled
的符号链接。dig +short example.com
。您的Nginx配置显示您有单独的server
块具有唯一server_name
值,因此通常您的配置看起来适合在单个IP地址上托管多个域。
(如果您碰巧剥离了SSL配置,可能存在相关问题,但我假设不是基于您的配置)。