1024programmer Nginx The matching domain name of Nginx pan analysis is bound to the subdirectory configuration

The matching domain name of Nginx pan analysis is bound to the subdirectory configuration

The directory structure of the website is:

  1. # tree /home/wwwroot/linuxeye.com

  2. /home/wwwroot/linuxeye.com

  3. ├── bbs

  4. │ └── index.html

  5. └── www

  6.   └── index.html

  7. 2 directories, 2 files

/home/wwwroot/linuxeye.com is the default path to store the source code in the nginx installation directory.

bbs is the source code path of the forum program; www is the source code path of the homepage program; put the corresponding program into the above path and pass; http://www.linuxeye.com visits the homepage http://bbs.linuxeye.com It is a forum, and other second-level domain names can be analogized.

There are 2 methods, recommended method 1

Method 1:

  1. server {

  2. listen 80;

  3. server_name ~^(?.+).linuxeye.com$;

  4. access_log /data/wwwlogs/linuxeye.com_nginx.log combined;

  5. index index.html index.htm index.php;

  6. root /home/wwwroot/linuxeye/$subdomain/;

  7. location ~ .php$ {

  8.   fastcgi_pass unix:/dev/shm/php-cgi.sock;

  9.   fastcgi_index index.php;

  10. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

  11. include fastcgi_params;

  12. }

  13. location ~ .*\.(gif|jpg|jpeg|png|bmp |swf|flv|ico)$ {

  14. expires 30d;

  15. }

  16. location ~ .*\.(js css)?$ {

  17. expires 7d;

  18. }

  19. }

Method Two:

  1. server {

  2. listen 80;

  3. server_name *.linuxeye.com;

  4. access_log /home/wwwlogs/linuxeye.com_nginx.log combined;

  5. index index.html index.htm index.php;

  6. if ($host ~* ^([^\ .]+)\.([^\.]+\.[^\.]+)$) {

  7. set $subdomain $1;

  8. set $domain $2;

  9. }

  10. location / {

  11. root /home/wwwroot/linuxeye.com/$subdomain/;

  12. index index.php index.html index.htm;

  13. }

  14. location ~ .php$ {

  15.   fastcgi_pass unix:/dev/shm/php-cgi.sock;

  16.   fastcgi_index index.php;

  17. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

  18. include fastcgi_params;

  19. }

  20. location ~ .*\.(gif|jpg|jpeg|png|bmp |swf|flv|ico)$ {

  21. expires 30d;

  22. }

  23. location ~ .*\.(js css)?$ {

  24. expires 7d;

  25. }

  26. }

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/the-matching-domain-name-of-nginx-pan-analysis-is-bound-to-the-subdirectory-configuration/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索