# NGINX issue with sub-domains



## scrummie02 (Feb 13, 2015)

So I have NGINX installed from the ports and it works well.  I've recently installed WP and want to run multi-site.

The issue is the sub domain stuff.  So when I go to http://domainname...I'm good. 
http://sub.domainname.com  no access.  I've configured NGINX hundreds of times before so I must be missing something.  Here is my server blocks

```
server {
    listen 80;

    server_name  domain.com *.domain.com;
    root        /opt/wordpress;
    index       index.php index.html index.htm;

    access_log /var/log/nginx/domain.access_log;
    error_log /var/log/nginx/domain.error_log;

    # Security
    include global/security.conf;
    #ModSecurityEnabled on;
    #ModSecurityConfig /usr/local/etc/modsecurity/modsecurity.conf;

    location / {
        # This is cool because no php is touched for static content.
        # include the "?$args" part so non-default permalinks doesn't break when using query string
        try_files $uri $uri/ /index.php?$args;
    }

        # PHP-FPM
        include global/php-fpm.conf;

        # STATICS FILES
    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires max;
        log_not_found off;
    }
}
```
I compiled with mod_security but have it remarked out.  I've used this config before on other boxes and it's always worked out for me well.

Here is the nginx.conf:

```
user www;

# Set this value to 1 or N with N = N-Core
worker_processes  2;
worker_rlimit_nofile 4096;
events {
        # max_clients = worker_processes * worker_connections
        worker_connections  1024;
        # Only for Linux 2.6 or >
        use kqueue;
        # Accept as many connections as possible
        multi_accept on;
}

http {
        # Mime types
        include         mime.types;
        default_type    application/octet-stream;

        # Log format
        set_real_ip_from        127.0.0.1;
        real_ip_header          X-Forwarded-For;
        log_format      main '$remote_addr - $remote_user [$time_local]  $status '
                '"$request" $body_bytes_sent "$http_referer" '
                '"$http_user_agent" "$http_x_forwarded_for"';

        # Hide the Nginx version number
        server_tokens off;

        # Some tweeks...
        sendfile                        on;
        tcp_nodelay                     on;
        #tcp_nopush                     on;

        # Timeouts
        #keepalive_timeout              10 10;
        keepalive_timeout               65;
        client_body_timeout             30;
        client_header_timeout           30;
        send_timeout                    30;
        client_max_body_size            8M;
        reset_timedout_connection       on;

        # Gzip module configuration
        gzip                    on;
        gzip_disable            "MSIE [1-6].(?!.*SV1)";
        gzip_vary               on;
        gzip_comp_level         3;
        gzip_proxied            any;
        gzip_buffers            16 8k;

        include /usr/local/etc/nginx/site-configuration/*;
    
}
```
What am I missing that's preventing the subdomains from being reachable.  I tend to have domain mapping installed as well but I need to get this working first.


----------



## junovitch@ (Feb 13, 2015)

The "server_name" directives look right.  What is in the access.log and error.log when you access the subdomain address?


----------



## storvi_net (Feb 14, 2015)

Could you try the "special" wildcard ".domain.com". It will match domain.com AND *.domain.com.

Cite from the doc: "A special wildcard name in the form “.example.org” can be used to match both the exact name “example.org” and the wildcard name “*.example.org”."
http://nginx.org/en/docs/http/server_names.html

Regards
Markus


----------



## Beeblebrox (Feb 16, 2015)

You are missing a whole bunch of code under location. Search for "wordpress codex nginx". Not all of it is necessary, but you must include the "location ^~ /blogs.dir" part:
http://codex.wordpress.org/Nginx
http://wiki.nginx.org/WordPress


----------

