Nginx与子目录

时间:2014-10-13 07:08:00

标签: nginx

我试图让以下配置在子目录/ dev中工作,但我对Nginx很新,并且似乎无法让它正常工作。

如果您查看以下配置,您会看到 内容 网站 等等。所有这些目录都位于另一个子目录 / dev 中。例如: root / dev / content root / dev / site 等。

任何人都可以伸出援手,以便我可以正确访问/ dev网站吗?

# block content
location ~ ^/content/(.*).(txt|md|mdown)$ {
    rewrite ^/content/(.*).(txt|md|mdown)$ /error redirect;
}

# block all files in the site folder from being accessed directly
location ~ ^/site/(.*)$ {
    rewrite ^/site/(.*)$ /error redirect;
}

# block all files in the kirby folder
location ~ ^/kirby/(.*)$ {
    rewrite ^/kirby/(.*)$ /error redirect;
}

# site links
location / {
    try_files $uri $uri/ /index.php?$uri&$args;
}

# panel links
location /panel {
    try_files $uri $uri/ /panel/index.php?$uri&$args;
}

# deny access to .htaccess files
location ~ /\.ht {
    deny all;
}

1 个答案:

答案 0 :(得分:0)

添加/ dev大部分配置解决了它。

# block content
location ~ ^/dev/content/(.*).(txt|md|mdown)$ {
    rewrite ^/dev/content/(.*).(txt|md|mdown)$ /error redirect;
}

# block all files in the site folder from being accessed directly
location ~ ^/dev/site/(.*)$ {
    rewrite ^/dev/site/(.*)$ /error redirect;
}

# block all files in the kirby folder
location ~ ^/dev/kirby/(.*)$ {
    rewrite ^/dev/kirby/(.*)$ /error redirect;
}

# site links
location /dev {
    try_files $uri $uri/ /dev/index.php?$uri&$args;
}

# panel links
location /dev/panel {
    try_files $uri $uri/ /dev/panel/index.php?$uri&$args;
}

# deny access to .htaccess files
location ~ /\.ht {
    deny all;
}