0

I created a staging subdomain for say, example.com and it works fine. Later, I created test.example.com and it doesn't serve files from it's configured directory. It just mirrors the parent domain.

In the DNS manager, I created test subdomain just like staging, then I created a config file for nginx again the same as staging, removed a previous host file entry that pointed test.example.com to 127.0.0.1, restarted the servers but in vain.

Point worthy of mention here is that I am using a SSL certificate for the parent domain. So the server name for parent domain is like this:

server {

    listen 443 ssl;
    server_name example.com www.example.com
 ...
}
...
...
server {
    listen 80;
    server_name  example.com www.example.com;
    return 301 https://$host$request_uri;
}

and for the test subdomain:

server {
    listen 80;
    server_name test.example.com
...
}

Could anyone kindly point me in the direction of a solution? I maybe missing something very basic.

1
  • Why are some people so quick to downvote I don't understand? This platform is for asking questions I believe. Do I have to show you my browser history to make you believe I did a lot of research for two days before posting a question here? – steady_daddy Aug 20 '17 at 17:07
1

Your server is behaving as though the new configuration has not come into effect.

Some nginx configurations use a symlink to a sites-enabled directory.

You need to restart nginx whenever its configuration is changed.

Use nginx -t to test the configuration file for syntax errors. If a running nginx fails to restart, it just continues to use the old configuration.

Use nginx -T to display the complete configuration across all include files, to ensure that the new configuration fragment is being read.

Clear the browser cache between each change to the nginx configuration to avoid erroneous test results.

3
  • I understand the symlink stuff, thank you, and I tested the configuration too. All looks fine. Yet the problem persists. – steady_daddy Aug 27 '17 at 16:53
  • Tried that but didn't see any error. – steady_daddy Sep 2 '17 at 12:23
  • Your answer was in the right direction but I could solve my problem only today when doing something similar. – steady_daddy Oct 29 '17 at 17:52
0

It was a really stupid mistake but it can certainly happen with anyone. Turns out it was only a matter of correctly creating symlinks for nginx vhosts. So for example if I had a configuration file named test, to create a symlink I was doing something like this:

sudo ln -s /etc/nginx/sites-available/test /etc/nginx/sites-enabled/test

instead of this:

sudo ln -s /etc/nginx/sites-available/test /etc/nginx/sites-enabled/

Hope this helps someone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.