N
N
Nadim Zakirov2020-07-25 19:39:29
Nginx
Nadim Zakirov, 2020-07-25 19:39:29

How to create all possible subdomains on nginx and direct to one site?

I'm trying to create a subdomain like *.localhost and here is my config:

server {
  listen 127.0.0.1:80;
  server_name localhost *.localhost;

  root home/localhost/public_html;

  index index.php index.html;

  log_not_found off;
  access_log logs/localhost-access.log main;

  charset utf-8;

  location ~ /\. { deny all; }
  location = /favicon.ico { }
  location = /robots.txt { }

  location ~ \.php$ {
    fastcgi_pass 127.0.0.1:9071;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
    include fastcgi_params;
  }

}

If it’s quite possible for me to visit localhost and the root file is visible, then from any subdomain on localhost I get a 404 error stating that the page (root document) of the type was not found. Please tell me what could be the problem? I use Winginx

as a local server .

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nadim Zakirov, 2020-07-26
@zkrvndm

The problem is solved, I had an error in this line in the configs:
location ~ /\. { deny all; }
Changed to to this and it all worked:
location / { }

M
Megum1n, 2020-07-25
@Megum1n

Add
listen 80 default_server ;
Then register * in dns for all subdomains.
Or specify
server_name *. example.com;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question