Apache2如何将子目录限制在本地网络

Apache2如何将子目录限制在本地网络

我有一台在 Ubuntu 20.04 上运行的 Apache2 (2.4.41) 服务器,它为几个 Flask Web 应用程序提供服务,这些应用程序通过 HTTPS 和 No-IP DDNS 连接到互联网,这些应用程序按子目录进行区分 (https://mysite.noip.com/site1, /site2 等...)。我想在同一台服务器上托管第三个 flask web 应用程序(例如 /site3),但只能在本地网络(192.168.1.x/site3 但不能在 mysite.noip.net/site3)上访问它,SSL 无关紧要,因为您只能通过服务器的本地 IP(192.168.1.x/site3)访问此站点,因此通过端口 80 运行是可以的,但是如何在 Apache2 中配置它?

我找不到任何关于通过子目录区分网站访问的信息,尤其是其中两个(/site1-2)通过 443 SSL 在外部运行。为了简化操作,我猜想我可以在另一个端口(192.168.1.x:81/site3)上运行此 site3,而不是通过路由器将其转发到互联网,但当我尝试这样做时,我只是弄乱了其他工作端口(80/443)。我的配置如下,任何有关从哪里开始的帮助或想法都将不胜感激!

站点已启用/000-默认.conf:

LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so

<VirtualHost *:80>
        RewriteEngine On
        RewriteCond %{HTTPS} off
        RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</VirtualHost>

<VirtualHost *:443>

        SSLEngine on
        SSLCertificateKeyFile /etc/apache2/ssl/#######.key
        SSLCertificateFile /etc/apache2/ssl/######.pem-chain
        #SSLCertificateChainFile /etc/apache2/ssl/######.pem
        XSendFile on
        XSendFilePath /######/######/########/

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        WSGIScriptAlias /site1 /home/#####/site1/site1.wsgi

        <Directory /home/######/site1/>
                Options FollowSymLinks
                AllowOverride None
                Require all granted
        </Directory>


        WSGIScriptAlias /site2 /home/#####/site2/site2.wsgi application-group=%{GLOBAL}

        <Directory /home/#######/site2/>
                Options FollowSymLinks
                AllowOverride None
                Require all granted
        </Directory>
</VirtualHost>

apache2ctl-S:

AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
VirtualHost configuration:
*:80                   127.0.1.1 (/etc/apache2/sites-enabled/000-default.conf:3)
*:443                  127.0.1.1 (/etc/apache2/sites-enabled/000-default.conf:9)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex rewrite-map: using_defaults
Mutex ssl-stapling-refresh: using_defaults
Mutex ssl-stapling: using_defaults
Mutex proxy: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/var/run/apache2/" mechanism=default
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33

答案1

https://httpd.apache.org/docs/2.4/howto/access.html

<RequireAll>
    Require all granted
    Require not ip 192.168.4.0/24
</RequireAll>

在你的<Directory>诗节里面应该可以达到这个目的。

与往常一样,Apache 手册非常好,文档详尽,包含大量有关如何操作的示例。

相关内容