Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Nginx Multiple Sites Issue

So currently I have nginx on my VPS setup for hosting a couple websites of mine.
One site is hosted/connecting just fine however it is using site files not in teh directory I specified.

For example:
Code
server {
    listen       80;
    server_name  domain1.com;
    root   /var/www/html/domain1.com;
    index  index.html index.htm index.php;

    location / {
        try_files $uri $uri/ =404;
    }

# add other directives here;

}

^ I have it setup so that the site files will come from domain1.com folder; however, when connecting to the site it just uses all files found in the root html directory. :/ hmmm...


Non the less atleast the site is working and is hosted.

But when I tried setting up my server to run a second domain I used essentially the same exact config accept for obviously I changed the domain.

And yes I've already put this in the nginx config file
Code
include /etc/nginx/sites-enabled/*.conf;

Also made sure to enable both of the sites with this command
Code
sudo ln -s /etc/nginx/sites-available/domain1.com /etc/nginx/sites-enabled/

All of this my second domain forwarded correctly yet it will not connect to the server...

Any suggestions??

Assistance is greatly appreciated 🤝
Helped him setup Nginx properly and fixed some minor DNS issues.

If you ever need anymore help, feel free to shoot me a PM or message me on Discord.

BTC:1TitanT8DDZmrrRs33avKvnUyH1nU6Cko
[Image: vt9fDYR.png]
(Apr 13, 2017 01:12 AM)Yani Wrote:  What was the issue?

On forums it's best to include a solution if one has been found, so people from the future might get helped without you even knowing it.

Oh yeah, no problem. The main issue that caused his problems were only having the subdomain of www. pointing to his domain and a few Nginx settings that needed to be changed.

Under server_name in the Nginx sites-available, he only had the domain listed when he needed to have both the domain and the www. domain listed.

Before
Code
server_name  domain1.com;
After
Code
server_name  domain1.com www.domain1.com;

As for DNS, he had WWW pointing to his IP but he didn't have @ pointing to his domain. So you could connect through the subdomain www. domain1 but not connect directly to the website. This lead to Nginx pointing the direct connection to the website to the default directory of his website folder, not the sub folder for the specific domain. After all of that, we then only needed to change two lines in his Nginx.conf that were incorrect.

Before
Code
#server_names_hash_bucket_size 64;
#server_name_in_redirect off;
After
Code
server_names_hash_bucket_size 64;
server_name_in_redirect on;

After that I helped show him some better practices when using Nginx and helped clear up some confusion.
Sorry about not posting the solution earlier, I don't know what I was thinking. 😝

BTC:1TitanT8DDZmrrRs33avKvnUyH1nU6Cko
[Image: vt9fDYR.png]
If you still need help with this, please PM me.


Possibly Related Threads...
Thread / Author Replies Views Last Post
by lgfINCApr 30, 2021 02:54 PM 1 162 Apr 30, 2021 02:54 PM
Last Post: Warrioя
by Rorschach.Feb 13, 2018 06:14 AM 14 283 Feb 13, 2018 06:14 AM
Last Post: Owl
by foxtrott50Sep 20, 2017 12:40 PM 13 292 Sep 20, 2017 12:40 PM
Last Post: SIM-1456221