關閉      標題:linux 下的 mapserver 8
內容:

/etc/apache2/apache.conf

ServerSignature off
ServerTokens Prod
<IfModule security2_module>
    SecRuleEngine on
    ServerTokens Full
    SecServerSignature "FeatherMountain WebServer V1.0"
</IfModule>

SetEnv MAPSERVER_CONFIG_FILE /var/www/cgi-bin/mapserver.conf



/etc/apache2/sites-enabled/000-default.conf

        ScriptAlias /cgi-bin/ /var/www/cgi-bin/

        <Directory "/var/www/cgi-bin">
            RewriteEngine On
            Require ip 127.0.0.1 ::1 211.20.175.247
            Options +ExecCGI -Indexes
            AllowOverride None
            # 設定 MapServer 的安全目錄(相對路徑參考)
            # 條件:如果 Query String 中包含 map=easymap_server/... (捕捉這段)
            # %1 = map= 之前的所有參數
            # %2 = map= 之後的路徑 (例如 easymap_server/8428.map)
            # %3 = map= 路徑之後的所有參數
            RewriteCond %{QUERY_STRING} ^(.*)map=(easymap_server/[^&]+)(.*)$

            # 規則:重寫請求,將路徑補全為絕對路徑
            # [PT] 代表 Pass Through (讓 CGI 繼續處理),[L] 代表 Last rule
            RewriteRule ^mapserv$ mapserv?%1map=/var/www/cgi-bin/%2%3 [PT,L]
            SetEnv MS_MAP_PATTERN "^/var/www/|easymap_server/"
        </Directory>
</VirtualHost>

a2enmod cgi
a2enmod rewrite
systemctl restart apache2