1

Question: how to create simple nginx config that will read folders structure as domains (test.local, myblog.local) and shows the page from this folders, including PHP?

Information: Windows 10 x64 build
Vagrant 1.9.5
VirtualBox 5.0.22 (latest)
Guest OS: Ubuntu Xenial x64 latest

So, i want to create simple nginx config, that will recreate folder structure. See my config file on pastebin.

Also here is a Vagrantfile config, which use SMB to mount a folder.

The structure of folders:

├───devhost.local
│   ├───log
│   └───public
│           index.html
│           index.php
│
└───test.local
    ├───log
    └───public
            index.html

The rights for files and folders for devhost:

ubuntu@ubuntu-xenial:~$ ls -la /var/www/html/devhost.local/
total 4
drwxr-xr-x 2 ubuntu www-data    0 Jun  7 11:17 .
drwxr-xr-x 2 ubuntu www-data 4096 Jun  7 12:44 ..
drwxr-xr-x 2 ubuntu www-data    0 Jun  7 11:17 log
drwxr-xr-x 2 ubuntu www-data    0 Jun  6 14:13 public

My hosts file in Windows:

192.168.33.10   devhost.local

So, when i have default config in my sites-enabled folder i can open guest machine through 192.168.33.10 and i see html page of nginx, but when i remove this default config and enable my wildcard config (see link my config file) so i cannot access my domains. The sudo nginx -t says that everything is ok, also i tried to restart my guest machine, reload/restart nginx service. Also, i disable Windows 10 Firewall (i dont know if its disabled fully, but says that its disabled). Also, the log files is empty and even not created, both access log and error log.

Where is my mistake? If need more information, please, ask me, i will give.

Thanks a lot!

V. Korovin
  • 149
  • 1
  • 3
  • 9

2 Answers2

0

following nginx setup should help.

server {
  listen 80 default_server;
  root /var/www/html/$host;
  index index.html index.php;
  location ~ \.php {
    # ... fastcgi details
  }
}
spiilmusic
  • 717
  • 3
  • 9
  • 24
  • The problem is the same. Chrome say that ERR_CONNECTION_REFUSED. Also, i disable ufw, but it not helps to solve the problem. – V. Korovin Jun 07 '17 at 17:09
0

I found the solution.

First of all, when i keep only one file with config, my nginx doesnt listen port 80, i check sudo netstat -ntlp | grep LISTEN but there wasnt port 80. So i Google, and found another question on stackoverflow (see link at the end).

Solution: recreate the simlink to my file with config, after that when i run sudo nginx -t i see a few errors. So its seems that before this files was empty or something like that, but i didnt notice this because i edit file directly in sites-available folder.

Thanks to everybody!

This question helps me to solve the problem: nginx not listening to port 80

V. Korovin
  • 149
  • 1
  • 3
  • 9