Hey everyone! I’m having an issue with my subdomain.

What I have right now is two sites-available/enabled with what seems like the right server block info. I have 2 separate unicorn service files in init.d and 2 project folders /main-host and /subdomain. Each folder has their respective unicorn files and nginx files/server blocks.

If i kill service unicornexample both the main site and the subdomain go down, but unicornsubdomain doesnt actually affect anything.

I’ll post everything I have.

nginx/sites-available/example.com

upstream subdomain {
    server unix:/home/rails/subdomain/shared/sockets/unicorn.sock fail_timeout=0;
}

server {
    listen   80;
    root /home/rails/subdomain/public;
    server_name www.subdomain.example.org subdomain.example.org;
    index index.htm index.html;

    location / {
            try_files $uri/index.html $uri.html $uri @app;
    }

    location ~* ^.+\.(jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|mp3|flv|mpeg|avi)$ {
                    try_files $uri @app;
            }

     location @app {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_redirect off;
            proxy_pass http://subdomain;
    }
}

nginx/sites-available/example

upstream app_server {
    server unix:/home/rails/example/shared/sockets/unicorn.sock fail_timeout=0;
}

server {
    listen   80;
    root /home/rails/example/public;
    server_name www.example.org example.org;
    index index.htm index.html;

    location / {
            try_files $uri/index.html $uri.html $uri @app;
    }

    location ~* ^.+\.(jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|mp3|flv|mpeg|avi)$ {
                    try_files $uri @app;
            }

     location @app {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_redirect off;
            proxy_pass http://app_server;
    }
}
server {
    listen   443;
    root /home/rails/example/public;
    server_name www.example.org example.org;
    index index.htm index.html;
    ssl on;


    location / {
            try_files $uri/index.html $uri.html $uri @app;
    }

    location ~* ^.+\.(jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|mp3|flv|mpeg|avi)$ {
                    try_files $uri @app;
            }

     location @app {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_redirect off;
            proxy_pass http://app_server;
    }
}

the important part of unicorn_example

USAGE="Usage: $0 <start|stop|restart|upgrade|rotate|force-stop>"

# app settings
USER="user"
APP_NAME="example"
APP_ROOT="/home/$USER/$APP_NAME"
ENV="production"

# environment settings
CMD="cd $APP_ROOT && bundle exec unicorn -c config/unicorn.rb -E $ENV -D"
PID="$APP_ROOT/shared/pids/unicorn.pid"
OLD_PID="$PID.oldbin"


important part of subdomain

USAGE="Usage: $0 <start|stop|restart|upgrade|rotate|force-stop>"

# app settings
USER="user"
APP_NAME="subdomain"
APP_ROOT="/home/$USER/$APP_NAME"
ENV="production"

# environment settings
CMD="cd $APP_ROOT && bundle exec unicorn -c config/unicorn.rb -E $ENV -D"
PID="$APP_ROOT/shared/pids/unicorn.pid"
OLD_PID="$PID.oldbin"

there aren’t any errors that I can find and I’ve checked everything I can think of. I think the issue lies with Nginx? With the subdomain dns setup, I created an A tag to point to the same IP and letting nginx take it from there. If you have any questions or need any more resources, let me know! Thanks for your help.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

Hello, @hello194962ece2671bd808e65

Could you please check if the subdomain’s DNS is properly resolving? You can either ping it from the console or use any website like https://www.whatsmydns.net/ to check the DNS propagation.

Keep in mind that any DNS change might take up to 48 hours in order to fully update due to DNS cache from all the ISPs. Usually it happens a lot faster, but it still takes time to propagate and start to resolve.

Hope this helps.

Regards,
Alex

Submit an Answer