nginx:为每个域设置一个webmail(通配域?)

我想设置一个networkingmail. 为我的服务器上的每个域使用nginx子域

它似乎在https://mail.mydomain.com上工作,但我也可以通过访问不需要的服务器IP地址( https:// xxxx )来访问networking邮件。

这是我的Web邮件的conf文件:

 ### # Webmail (Rainloop) ### server { listen 80; server_name mail*.; return 301 https://$host$request_uri; } server { listen 443 ssl; server_name mail*.; ssl_certificate /etc/ssl/nginx/server.crt; ssl_certificate_key /etc/ssl/nginx/server.key; ssl_protocols SSLv3 TLSv1; ssl_ciphers HIGH:!aNULL:!MD5; access_log /var/log/nginx/app-webmail.access.log; error_log /var/log/nginx/app-webmail.error.log; location / { root /var/www/rainloop; index index.html index.htm index.php; location ~ [^/]\.php(/|$) { include fcgi.conf; fastcgi_pass unix:/var/run/php-fcgi.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } location ^~ /data { deny all; } } } 

任何想法?

基于这个答案 ,默认的Nginxconfiguration已经改变如下:

/etc/nginx/nginx.conf

 server { listen 80; server_name <ip_address_nginx_server>; root /usr/share/nginx/html; #charset koi8-r; #access_log /var/log/nginx/host.access.log main; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { } # redirect server error pages to the static page /40x.html # error_page 404 /404.html; location = /40x.html { } # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { } return 403; } server { listen 80 default_server; server_name mydomain.com; } } 

一旦Nginx服务器重新启动,一个导航到ip_address_nginx_server返回403,而http://example.com是可访问的。

根据Nginx的文档,可以在服务器名称中使用这种通配符。

 server { listen 80; server_name mail.*; ... } 

但是,你有mail*. 而不是mail.*那里,这是真的不同的事情。