Раздел 10. Apache modules Пункты: 85 86 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 163 164 165 166 167 168 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 203 204 205 206 207 208 209 210 211 212 213 RU EN Пункт 163. Apache Module mod_macro
SummaryProvides macros within Apache httpd runtime configuration files, to ease the process of creating numerous similar configuration blocks. When the server starts up, the macros are expanded using the provided parameters, and the result is processed as along with the rest of the configuration file. UsageMacros are defined using For example, you might use a macro to define a <Macro VHost $name $domain> <VirtualHost *:80> ServerName $domain ServerAlias www.$domain DocumentRoot "/var/www/vhosts/$name" ErrorLog "/var/log/httpd/$name.error_log" CustomLog "/var/log/httpd/$name.access_log" combined </VirtualHost> </Macro> Macro names are case-insensitive, like httpd configuration directives. However, variable names are case sensitive. You would then invoke this macro several times to create virtual hosts: Use VHost example example.com Use VHost myhost hostname.org Use VHost apache apache.org UndefMacro VHost At server startup time, each of these The A more elaborate version of this example may be seen below in the Examples section. TipsParameter names should begin with a sigil such as Parameters prefixed with either Avoid using a parameter which contains another parameter as a prefix,
(For example, If you want to use a value within another string, it is useful to surround the parameter in braces, to avoid confusion: <Macro DocRoot ${docroot}> DocumentRoot "/var/www/${docroot}/htdocs" </Macro> ExamplesVirtual Host DefinitionA common usage of ## Define a VHost Macro for repetitive configurations <Macro VHost $host $port $dir> Listen $port <VirtualHost *:$port> ServerName $host DocumentRoot "$dir" # Public document root <Directory "$dir"> Require all granted </Directory> # limit access to intranet subdir. <Directory "$dir/intranet"> Require ip 10.0.0.0/8 </Directory> </VirtualHost> </Macro> ## Use of VHost with different arguments. Use VHost www.apache.org 80 /vhosts/apache/htdocs Use VHost example.org 8080 /vhosts/example/htdocs Use VHost www.example.fr 1234 /vhosts/example.fr/htdocs Removal of a macro definitionIt's recommended that you undefine a macro once you've used it. This avoids confusion in a complex configuration file where there may be conflicts in variable names. <Macro DirGroup $dir $group> <Directory "$dir"> Require group $group </Directory> </Macro> Use DirGroup /www/apache/private private Use DirGroup /www/apache/server admin UndefMacro DirGroup <Macro> Directive
The <Macro LocalAccessPolicy> Require ip 10.2.16.0/24 </Macro> <Macro RestrictedAccessPolicy $ipnumbers> Require ip $ipnumbers </Macro> UndefMacro Directive
The UndefMacro LocalAccessPolicy UndefMacro RestrictedAccessPolicy Use Directive
The Use LocalAccessPolicy ... Use RestrictedAccessPolicy "192.54.172.0/24 192.54.148.0/24" is equivalent, with the macros defined above, to: Require ip 10.2.16.0/24 ... Require ip 192.54.172.0/24 192.54.148.0/24 Пункты: 85 86 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 163 164 165 166 167 168 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 203 204 205 206 207 208 209 210 211 212 213 |