ドキュメント

Virtual hosts

All websites in Winginx are processed automatically by a default config. So, if you create a folder like this winginx\home\mysite.local\public_html, the website will be at work soon (no restart is needed) with URL http://mysite.local/ or http://www.mysite.local/. Don't forget to place this domain name in the hosts file manually or using HostsEditor.

The automatic configuration has the following settings:

  • A listen directive is set to 127.0.0.1:80
  • A server_name directive has value to mysite.local and its www alias — www.mysite.local
  • Access log (access_log): winginx\logs\mysite.local-access.log
  • Index files (index): index.php index.html
  • Default charset (charset): utf-8

Locations (location):

# deny all requests starting with a dot (.htaccess, .user.ini, etc.)
location ~ /\. {
  deny all;
}

# usual location for all requests starting with a slash /
location / {
}

# locations for favicon.ico and robots.txt for fast URL processing
location = /favicon.ico { }
location = /robots.txt { }

# PHP location:
location ~ \.php$ {
  if (!-e $document_root$document_uri){
    return 404;
  }
  fastcgi_pass localhost:9000;
  fastcgi_index index.php;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  include fastcgi_params;
}

This config is suitable in almost all cases.

But some times you may need an individual settings for a website, in this case you should create in the winginx\conf\vhosts folder a separate config file named to domain name plus .conf, e.g. mysite.local.conf.

After the config is added or edited, you should restart Winginx, double-click start-winginx.exe.

If something goes wrong after these manipulates, please read winginx\logs\error.log.

Here there are some examples.

Error pages 404, 403, etc.

server {
  listen   127.0.0.1:80;
  server_name  test.local www.test.local;

  root home/test.local/public_html;
  index index.php index.html;

  log_not_found off;
  charset utf-8;

  access_log  logs/test.local-access.log  main;

  error_page 404  /404.html;
  error_page 403  /403.html;

  location ~ /\. {
    deny all;
  }

  location / {
  }

  location ~ \.php$ {
    if (!-e $document_root$document_uri){
      return 404;
    }
    fastcgi_pass localhost:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
  }
}

Configuring of index files

server {
  listen   127.0.0.1:80;
  server_name  test.local www.test.local;

  root home/test.local/public_html;
  index default.php default.html;

  ...

  location ~ \.php$ {
    if (!-e $document_root$document_uri){
      return 404;
    }
    fastcgi_pass localhost:9000;
    fastcgi_index default.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
  }
}

Changing port from 80 to ... 8001 (any other)

server {
  listen   127.0.0.1:8001;
  server_name  test.local www.test.local;

  ...

}

Adding aliases

server {
  listen   127.0.0.1:80;
  server_name  test.local www.test.local test2.local test3.local test4.local;
  # не забываем добавить перечисленные домены в hosts
  ...

}

Joining Node.js and PHP

server {
  listen   127.0.0.1:80;
  server_name  test.local www.test.local;

  root home/test.local/public_html;
  index index.php index.html;

  log_not_found off;
  charset utf-8;

  access_log  logs/test.local-access.log  main;

  location ~ /\. {
    deny all;
  }

  location / {
    if (!-e $request_filename) {
      # if a file is missing, passing to Node.js
      proxy_pass http://localhost:1337;
    }
  }

  # files with the .php extensions are for PHP
  location ~ \.php$ {
    if (!-e $document_root$document_uri){
      return 404;
    }
    fastcgi_pass localhost:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
  }

  # second case, special URL for Node.js
  location /chat/ {
    if (!-e $request_filename) {
      # if a file is missing, passing to Node.js
      proxy_pass http://localhost:1337;
    }
  }
}
Winginx © Alexei Shabalin, 2011-2023