nginx virtual host configuration example details

  • 2020-05-13 04:38:31
  • OfStack

nginx virtual host configuration


server {
  listen    80;
  server_name localhost;
  
  location / {
    root  html;
    index index.html index.htm;
  }

  error_page 404       /404.html;

  # redirect server error pages to the static page /50x.html
  # error_page  500 502 503 504 /50x.html;
  location = /50x.html {
  root  html;
  }
} 

Configuration instructions:

listen 80; = > Specify that the virtual host is listening on port 80
server_name localhost; = > Specify the virtual host domain name
location / { ... } = > Match the request path, / means match all requests
root html; = > The physical root directory of the specified virtual host, eg and html, is located at D:\div\nginx-1.9.14\html\
index index.html index.htm; = > Specify the default home page for the virtual host. The default home page is located in the directory D:\div\nginx-1.9.14\html

Thank you for reading, I hope to help you, thank you for your support of this site!


Related articles: