Amazon web services 始终捕获正则表达式的nGinx服务器名称(ec2)

Amazon web services 始终捕获正则表达式的nGinx服务器名称(ec2),amazon-web-services,nginx,Amazon Web Services,Nginx,有一个ec2服务器,它有不同的子域,我希望指向不同的服务,尝试使用服务器名称来捕获每个服务,但不工作,总是默认为first conf(admin)。在下面的示例中,我希望example.com使用default.conf,admin.example.com使用admin.conf #nginx.conf http { include /etc/nginx/mime.types; default_type application/octet-stream; lo

有一个ec2服务器,它有不同的子域,我希望指向不同的服务,尝试使用服务器名称来捕获每个服务,但不工作,总是默认为first conf(admin)。在下面的示例中,我希望example.com使用default.conf,admin.example.com使用admin.conf

#nginx.conf

http {

    include   /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    keepalive_timeout  65;

    gzip  on;
    gzip_comp_level 9;
    gzip_proxied any;
    gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript applicat$
    gzip_min_length  1000;
    gzip_disable     "MSIE [1-6]\.";

    underscores_in_headers on;

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*.conf;

    index   index.html index.htm;

}


#/sites-enabled/default.conf

server {

    listen 80;
    server_name localhost;
    root /usr/share/nginx/html;

}


#/sites-enabled/admin.conf

server {

    listen 80;

    server_name ^(www\.)?admin(-dev|-sandbox|)$ *.example.com;
    #server_name admin.example.com # This is still caught by all routes

    access_log  /var/log/nginx/admin.access.log;

    location / {
            root /usr/share/admin-frontend;
            index index.html index.html;
    }

}
我已经设置了hosts文件

127.0.0.1 localhost
127.0.0.1 admin.localhost
127.0.0.1 admin-dev.localhost
127.0.0.1 admin-sandbox.localhost
当前,如果我使用ec2()的公共dns,则即使服务器不匹配,也会触发管理配置。

尝试此regexp:

server_name ~^(www\.)?admin(-dev|-sandbox|)\.example\.com$;
我在你的主机文件中找不到*.example.com域,也许你也需要添加它们

127.0.0.1 example.com admin.example.com admin-dev.example.com

etc

example.com就是一个例子,我为实际域设置了它:),所以只需使用所需的域名尝试regexp)