Nginx bind a generic resolved matching domain name to a subdirectory configuration method _nginx

Source: Internet
Author: User
Tags subdomain

The directory structure of the Web site is:

# tree/home/wwwroot/exehack.net
/home/wwwroot/exehack.net
├──bbs
│└──index.html
└──www
└──index.html
2 directories, 2 files

/home/wwwroot/exehack.net is the path to the default source code for the Nginx installation directory.
BBS for the Forum program source code path, www for the home Page program source code path, the corresponding program into the above path through; http://www.exehack.net access is the home page http://bbs.exehack.net access is the forum, the other two-level domain name analogy.
There are 2 ways to recommend the method of a

 server {
listen;
Server_Name ~^ (? <subdomain>.+). exehack.net$;
Access_log/data/wwwlogs/exehack.net_nginx.log combined;
Index index.html index.htm index.php;
root/home/wwwroot/linuxeye/$subdomain/;
Location ~. php$ {
  fastcgi_pass unix:/dev/shm/php-cgi.sock;
  Fastcgi_index index.php;
  Fastcgi_param script_filename $document _root$fastcgi_script_name;
  Include Fastcgi_params;
  }
Location ~. *\. (Gif|jpg|jpeg|png|bmp|swf|flv|ico) $ {
  expires 30d;
  }
Location ~. *\. (JS|CSS)? $ {
  expires 7d;
  }
}

Method Two,

 server {
listen;
server_name *.exehack.net;
Access_log/home/wwwlogs/exehack.net_nginx.log combined;
Index index.html index.htm index.php;
if ($host ~* ^ ([^\.] +)\. ([^\.] +\. [^\.] +) $ {
  set $subdomain $;
  Set $domain $
}
Location/{
  root/home/wwwroot/exehack.net/$subdomain/;
  Index index.php index.html index.htm;
}
Location ~. php$ {
  fastcgi_pass unix:/dev/shm/php-cgi.sock;
  Fastcgi_index index.php;
  Fastcgi_param script_filename $document _root$fastcgi_script_name;
  Include Fastcgi_params;
  }
Location ~. *\. (Gif|jpg|jpeg|png|bmp|swf|flv|ico) $ {
  expires 30d;
  }
Location ~. *\. (JS|CSS)? $ {
  expires 7d;
  }
}

Nginx the configuration method that binds a pan-resolved matching domain name to a subdirectory is as follows

Copy Code code as follows:

server {
Listen 80;
server_name domain.com *.domain.com;

if ($host ~* ^ ([^\.] +)\. ([^\.] +\. [^\.] +)$) {
Set $subdomain $;
Set $domain $;
}

Location/{
root/home/wwwroot/$domain/$subdomain/;
Index index.php index.html index.htm;
#include/home/wwwroot/$domain/$subdomain/.ngx.htaccess;
}

Error_page 502 503 504/50x.html;

Location =/50x.html {
root HTML;
}

Location ~ \.php$ {
root/home/wwwroot/$domain/$subdomain/;
Fastcgi_pass 127.0.0.1:9100;
Fastcgi_index index.php;
Fastcgi_param script_filename $document _root$fastcgi_script_name;
Include Fastcgi_params;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.