zodream梦想开源/个人编程日记

zodream梦想开源/个人编程日记

简单的个人编程日记

马上订阅 zodream梦想开源/个人编程日记 RSS 更新: https://zodream.cn/blog/rss

nginx 子目录匹配不同地方的文件夹

2019年11月2日 02:41
编程技术

nginx 子目录匹配不同地方的文件夹

要求

/ 对应 /data/www

/shop 对应 /home/www/shop

/task 对应 /home/task1

/shop/h5 对应 /data/www/shop/h5

/bbs/index.php 对应 /data/bbs/index.php

第一个

server
{
    listen       80 default;
    server_name  zodream.cn;
    rewrite ^(.*)$ https://${server_name}$1 permanent; # 强制使用https 访问
}

server
{
    listen       443 ssl;
    server_name  zodream.cn;
    index index.html index.htm index.php;
    root  /data/www;
    ssl_certificate /data/ssl/zodream.cn.pem;
    ssl_certificate_key /data/ssl/zodream.cn.key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ALL:!DH:!EXPORT:!RC4:+HIGH:+MEDIUM:!LOW:!aNULL:!eNULL;

    location / {
    }

    location ~ ^/shop/h5/.+\.php {
        root /data/www;
        include php_fcgi.conf;
    }


    location ~ ^/shop/h5.* {
        root /data/www;
    }

    location /shop {
        root /home/www; # 会访问 /home/www/shop 文件下的所有html文件,不能访问其他类型文件
    }

    location ~ ^/shop {
        root /home/www; # 会访问 /home/www/shop 文件下的所有类型的文件
    }


    location ~ ^/task.* {
        root /home/task1;
        rewrite ^/task(.*)$ /$1 break;    # 这种方法跟上一种方法效果一样但不需要保持文件名一致
    }

    location ~ ^/bbs/.*\.php.* {       # 此方法存在一个问题即默认的 /bbs php程序提示找不到文件   
        root /data/bbs/;
        include php_fcgi.conf;
        set $real_script_name $fastcgi_script_name;
        if ($fastcgi_script_name ~ "^/bbs/(.+?\.php)(.*)$") {
            set $real_script_name $1;
            set $path_info $2;
        }
        fastcgi_param...

剩余内容已隐藏

查看完整文章以阅读更多