Answer the question
In order to leave comments, you need to log in
Setting up nginx hosts and default?
Sysadmins, help me out.
Ubuntu 20 nginx + php-fpm 7.4
All day long trying to figure out why it works this way and not otherwise.
I have a domain attached to the VPS from the hoster: https://vm2888385.33ssd.had.wf/
I also attached mine and redirected it to the server IP via the A records: https://vladislav.in/
Installed nginx and puff and configured the host for the second link.
I need the subdomain still in a separate folder. So you need to create another config file, did it, everything opens the site too: https://files.vladislav.in/
And the situation turns out to be:
1. We go to the site https://vm2888385.33ssd.had.wf/ - nginx opens folder for files.vladislav.in
2. Go tohttps://vladislav.in/ - everything is ok, opens the vladislav.in folder
3. Go to https://files.vladislav.in/ everything is ok opens your folder
4. Go to https://213.166.70.205/ opens the folder for files.vladislav.in
Why does it lead to a subdomain by default? And how to fix it.
Below I attach the configs:
/etc/nginx/conf.d/default.conf
server {
listen 80;
server_name _;
location / {
root /var/www/html;
index index.php index.html index.htm;
}
}
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
}
server {
charset utf-8;
client_max_body_size 128M;
listen vladislav.in:443 ssl;
#listen [::]:80 default_server ipv6only=on;
ssl_certificate /etc/letsencrypt/live/vladislav.in/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/vladislav.in/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/vladislav.in/chain.pem;
ssl_stapling on;
ssl_stapling_verify on;
resolver 127.0.0.1 8.8.8.8;
server_name vladislav.in;
root /var/www/vladislav.in;
index index.html index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
try_files $uri =404;
}
error_page 404 /404.html;
location ~ \.php$ {
include fastcgi.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
location ~ /\.(ht|svn|git) {
deny all;
}
}
server {
charset utf-8;
client_max_body_size 128M;
listen files.vladislav.in:443 ssl;
#listen [::]:80 default_server ipv6only=on;
ssl_certificate /etc/letsencrypt/live/files.vladislav.in/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/files.vladislav.in/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/files.vladislav.in/chain.pem;
ssl_stapling on;
ssl_stapling_verify on;
resolver 127.0.0.1 8.8.8.8;
server_name files.vladislav.in;
root /var/www/files.vladislav.in;
index index.html index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
try_files $uri =404;
}
error_page 404 /404.html;
location ~ \.php$ {
include fastcgi.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
location ~ /\.(ht|svn|git) {
deny all;
}
}
Answer the question
In order to leave comments, you need to log in
How to make a site from the /var/www/html folder open when opening an IP or domain from a hoster
listen 80 default_server;
listen [::]:80 default_server;
location / {
return 444; # Reset connection
}
listen files.vladislav.in:443 ssl;
This is how you can't do it. Or we specify IP (if you have several of them) or we specify only the port. The server_name directive is responsible for the website domain . listen 80; # http IPv4
listen [::]:80; # http IPv6
listen 443 ssl; # https IPv4
listen [::]:443 ssl; # https IPv6
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question