Nginx与子目录(Nginx with subdirectory)

编程入门 行业动态 更新时间:2024-10-06 19:19:39
Nginx与子目录(Nginx with subdirectory)

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

如果查看以下配置,您将看到子目录,例如内容站点等。所有这些目录都位于另一个子目录/ dev中 。 例如: root / dev / contentroot / 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; }

I'm trying to get the following configuration to work inside a subdirectory /dev but I'm quite new to Nginx and can't seem to get it to work properly.

If you look at the below configuration, you'll see subdirectories such as content, site, etc. All of those directories are inside another subdirectory /dev. For example: root/dev/content, root/dev/site, etc.

Can anyone lend a hand so that I can access the /dev site properly?

# 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; }

最满意答案

添加/ 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; }

Adding /dev to most of the config solves it.

# 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; }

更多推荐

本文发布于:2023-08-04 02:11:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1408585.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:与子   目录   Nginx   subdirectory

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!