포트 80 및 443에 대한 Virtualhost 지시문을 복제해야합니까?
길고 복잡한 <VirtualHost> 지시문 목록이 있으며 SSL을 사용하고 있으므로 포트 80 및 443에 대해 별도의 <VirtualHost> 그룹으로 복제해야합니다. mod_rewrite 규칙을 업데이트 할 때마다 두 곳 모두에서 수행해야한다는 것을 기억해야합니다. 그렇지 않으면 앱이 손상됩니다.이 중복은 문제를 야기합니다. 이들을 결합하거나 별칭을 지정하는 방법이 있습니까? 둘의 유일한 차이점은 포트 443 버전에 SSLEngine, SSLCertificateFile 등이 포함되어 있다는 것입니다.
내 <Virtualhost>에는 많은 mod_rewrite 규칙, LocationMatch 규칙, CGI 지시문 등이 포함되어 있습니다.
또한 .htaccess 파일을 사용할 수 없습니다.
공통 규칙을 포함하기 위해 include 지시문을 사용할 수 없습니다. 여기
예 :
<VirtualHost _default_:80>
...
include conf/common_rule.conf
</VirtualHost>
<VirtualHost _default_:*>
...
include conf/common_rule.conf
</VirtualHost>
<VirtualHost _default_:443>
... #SSL rules
include conf/common_rule.conf
</VirtualHost>
단일 Virtualhost 지시문에서 호스트 및 포트의 수를 사용할 수 있습니다.
<VirtualHost addr[:port] [addr[:port]] ...> ... </VirtualHost>
내 경우에는 사용했습니다.
<VirtualHost *:80 *:443>
ServerName loop.lk
....
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/local.crt
</VirtualHost>
이와 같은 오래된 게시물을 올려서 미안하지만 다른 Google 직원을 돕기 위해 어떻게 처리했는지 공유하고 싶었습니다.
내 로컬 호스트에 가상 호스트의 몇 가지를 가지고 말 : localhost
, foo.com
,bar.com
이것은 내 랩톱 (macosx)의 로컬 호스트 사이트이므로 자체 서명 된 인증서로 벗어날 수 있으므로 ssl-part는 모든 가상 호스트에서 동일합니다 ...
내가 한 일은 다음과 같습니다.
디렉토리를 만들었습니다 /etc/apache2/extra/vhosts/
.
나는 만들었습니다 /etc/apache2/extra/vhosts/localhost.conf
:
ServerName localhost
DocumentRoot "/www/localhost"
<Directory /www/localhost>
Require all granted
</Directory>
ErrorLog "/var/log/apache2/localhost.error_log"
CustomLog "/var/log/apache2/localhost.access_log" common
A /etc/apache2/extra/vhosts/foo.conf
:
ServerName foo.com
DocumentRoot "/www/foo.com"
<Directory /www/foo.com>
Require all granted
</Directory>
ErrorLog "/var/log/apache2/foo.com.error_log"
CustomLog "/var/log/apache2/foo.com.access_log" common
A /etc/apache2/extra/vhosts/bar.conf
:
ServerName bar.com
DocumentRoot "/www/bar.com"
<Directory /www/bar.com>
Require all granted
</Directory>
ErrorLog "/var/log/apache2/bar.com.error_log"
CustomLog "/var/log/apache2/bar.com.access_log" common
그리고 마지막으로 /etc/apache2/extra/vhosts/ssl.conf
:
SSLEngine on
SSLCertificateFile "/etc/apache2/ssl/server.crt"
SSLCertificateKeyFile "/etc/apache2/ssl/server.key"
그리고 내 /etc/apache2/extra/httpd-vhosts.conf
:
<VirtualHost *:80>
Include /etc/apache2/extra/vhosts/localhost.conf
</VirtualHost>
<VirtualHost *:443>
Include /etc/apache2/extra/vhosts/localhost.conf
Include /etc/apache2/extra/vhosts/ssl.conf
</VirtualHost>
<VirtualHost *:80>
Include /etc/apache2/extra/vhosts/foo.conf
</VirtualHost>
<VirtualHost *:443>
Include /etc/apache2/extra/vhosts/foo.conf
Include /etc/apache2/extra/vhosts/ssl.conf
</VirtualHost>
<VirtualHost *:80>
Include /etc/apache2/extra/vhosts/bar.conf
</VirtualHost>
<VirtualHost *:443>
Include /etc/apache2/extra/vhosts/bar.conf
Include /etc/apache2/extra/vhosts/ssl.conf
</VirtualHost>
사용하는 대신 또 다른 옵션 Include
은 사용 Macro
하는 것입니다 (하나의 파일에 모두 보관할 수 있음).
먼저 매크로 모듈을 활성화합니다.
a2enmod macro
Then put your shared stuff in a macro and use
it from your virtualhosts:
<Macro SharedStuff>
ServerName example.com
ServerAdmin example@example.com
<DocumentRoot /var/www/example>
...
</DocumentRoot>
</Macro>
<VirtualHost *:80>
Use SharedStuff
</VirtualHost>
<VirtualHost *:443>
Use SharedStuff
SSLEngine On
SSLProtocol All -SSLv2 -SSLv3
...
</VirtualHost>
Macros can also take parameters, and be defined in other files that are included; so you can use them a bit like Functions, and save a lot of duplication across your Apache config files.
See here for more details:
https://httpd.apache.org/docs/2.4/mod/mod_macro.html
You could put the common configuration into a separate file and include it in both VirtualHost segments. For example:
<VirtualHost 192.168.1.2:80>
Include conf/common.conf
</VirtualHost>
<VirtualHost 192.168.1.2:443>
Include conf/common.conf
(put your ssl specific cofiguration stuff here ...)
</VirtualHost>
You could also specify the common directives within a container instead of within the itself. That's what I do, mostly because I prefer mod_rewrite rules at the directory level instead of at the server level, but it should work equally well for you too.
'code' 카테고리의 다른 글
OpenAI에서 새로운 체육관 환경을 만드는 방법은 무엇입니까? (0) | 2020.12.12 |
---|---|
Xcode 10.2가 iOS 10 미만의 시뮬레이터에서 앱을 실행하지 못했습니다. (0) | 2020.12.12 |
OSX에 LaTeX .sty 파일을 어떻게 설치합니까? (0) | 2020.12.12 |
파이썬에서 시간 델타 비교 (0) | 2020.12.12 |
svg 좌표계 반전 (0) | 2020.12.12 |