아파치의 httpd.conf 파일에서 변수를 정의하는 방법은 무엇입니까?
Apache 서버의 httpd.conf구성 파일에 변수를 정의하고 싶습니다 .
예 : 변수 static_path = C:\codebase\snp_static
httpd.conf필요한 곳 에서이 변수 (static_path)를 사용하고 싶습니다 .
httpd.conf파일 에서 변수를 어떻게 정의 할 수 있는지 알려주세요 .
httpd.conf 내에서 다음을 사용 하여 변수를 선언하십시오. Define(바람직하게는 첫 번째 줄에)
구문 :Define variable-name variable-value
이런 방법으로:
#The line below creates the variable [static_path]
Define static_path C:/codebase/snp_static
나중에 다음과 같이이 변수를 사용할 수 있습니다.
ServerRoot = ${static_path}
...
DocumentRoot = ${static_path}
...
<Directory ${static_path}>
...etc.
여러 변수를 결합 할 수도 있습니다.
#Below, I am going to combine variables [server_space] and [static_path]
Define server_space c:/
Define static_path codebase/snp_static
...
ServerRoot = ${server_space}${static_path}
...
DocumentRoot = ${server_space}${static_path}
...
<Directory ${server_space}${static_path}>
...etc.
문서 : http://httpd.apache.org/docs/2.4/mod/core.html#define
httpd.conf 내에서 간단한 변수 대체 만 원하는 경우 Apache를 실행하는 사용자에 대한 일반 셸 환경 변수를 정의한 다음 $ {ENVVAR} 구문을 사용하여 httpd.conf 파일 내에서 참조하십시오. Apache 문서를 참조하십시오.
Apache2.4 나는 그것을 조사했고 여기에 나를 위해 일한 것이 있습니다. httpd_z.exe -t -D DUMP_RUN_CFG를 사용하여 테스트했습니다.
RESULTS:::
ServerRoot: "C:/path/core/apache2"
Main DocumentRoot: "C:/path/apache/htdocs"
Main ErrorLog: "C:/path/core/apache2/logs/error.log"
Mutex rewrite-map: using_defaults
Mutex default: dir="C:/path/core/apache2/logs/" mechanism=default
PidFile: "C:/path/core/apache2/logs/httpd.pid"
Define: DUMP_RUN_CFG
Define: US_ROOTF=C:/path **THIS IS THE ROOT PATH VARIABLE I JUST MADE**
Define: php54
#<IfDefine TEST>
# Define servername test.example.com
#</IfDefine>
#<IfDefine !TEST>
# Define servername www.example.com
# Define SSL
#</IfDefine>
#DocumentRoot /var/www/${servername}/htdocs
<IfDefine US_ROOTF>
Define US_ROOTF C:/PATH **The path i want the variable for**
</IfDefine>
<IfDefine !US_ROOTF>
Define US_ROOTF C:/PATH **The path i want the variable for**
# Define SSL
</IfDefine>
#DocumentRoot /var/www/${servername}/htdocs OPTIONS ON HOW TO USE
EXAMPLE of use
ServerRoot = ${US_ROOTF}
<IfDefine php54>
LoadFile "${US_ROOTF}/core/php54/icudt53.dll"
PHPIniDir "${US_ROOTF}/core/php54/php_production.ini"
나는 인터넷에 무언가를 제공 할 때 어떤 것에 대한 직접적인 HARD 경로를 사용하지 말라고 들었습니다. 항상 변수를 사용하여 시스템을 보호합니다.
나는 이것이 사실이라는 어려운 방법을 발견했습니다. 이제 마침내 Apache를 다루는 모든 서비스에 대한 변수를 설정하는 방법을 알아 냈습니다.
그것이 당신에게도 도움이되기를 바랍니다.
질문에 늦었지만 최근 에이 문제가 발생하여 다음과 같이 수정되었습니다.
DEFINE path "C:\path/to the/directory"
그런 다음 나중에 다음과 같이 사용하십시오.
DocumentRoot ${path} <Directory ${path}>
참고 : 경로에서 드라이브 문자 뒤에 \를 사용 하십시오.
참고URL : https://stackoverflow.com/questions/6569080/how-to-define-a-variable-in-apaches-httpd-conf-file
'Program Club' 카테고리의 다른 글
| window.location.href 변경시 이벤트 (0) | 2020.12.11 |
|---|---|
| $ request_body에서 POST 데이터 로깅 (0) | 2020.12.11 |
| 특정 디렉토리의 경로없이 파일 이름 가져 오기 (0) | 2020.12.11 |
| Node.js-Mongoose로 관계 만들기 (0) | 2020.12.11 |
| Go에서 런타임에 해당 유형에서 구조체의 새 인스턴스를 만드는 방법은 무엇입니까? (0) | 2020.12.11 |