I
I
Ivan Vasilich2018-12-09 23:13:05
Nginx
Ivan Vasilich, 2018-12-09 23:13:05

How to add multiple websites to one port in nginx?

Good afternoon. there is a home server on nginx ports 80 and 443 are open. it has a website mywebsite.com i
want to add a new website on the same port nothing works.
create config in /etc/nginx/sites-available/mysecondwebsite.com
and sim link ln -s mysecondwebsite.com ../sites-enabled/mysecondwebsite.com

server {
    listen 80;
    listen [::]:80 ipv6only=on;

    root /var/www/mysecondwebsite.com;
    index index.html;

    server_name mysecondwebsite.com;

    location / {
        try_files $uri/ /index.html?$args;
    }
}

but it constantly redirects me to the first website, what am I doing wrong why it does not open the second website

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Maxim Klyushkov, 2018-12-09
@m_klyushkov

The config looks correct, you need to make sure that it is loaded, look at the access / error logs.
I usually do symlinks a little differently:
It is very useful to make separate access.log for each virtual server

I
Ivan Vasilich, 2018-12-10
@jcmax

How can I check if the host is loaded or not? log files were created but there is nothing in them

B
BoJIaHq, 2018-12-11
@BoJIaHq

as I see it, there are two options for solving the problem, maybe I'm wrong ...
if there is an opportunity, for example, you can do this
server {
listen 80;
server_name domain.com;
location /mywebsite {
.......
}
location /mysecondwebsite {
.......
}
}
or create two config files
mywebsite.conf and mysecondwebsite.conf and
write
server {
listen 80;
server_name mywebsite.com;
}
server {
listen 80;
server_name mysecondwebsite.com;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question