sudo apt install apache2 -y # 설치
systemctl start apache2 # 실행
systemctl status apache2 # 상태 확인
systemctl stop apache2 # 종료
systemctl restart apache2 # 재실행
systemctl reload apache2 # 재로드(설정파일 변경시)
apachectl configtest # 설정 파일 오류 확인
# 정상
Syntax OK
# 오류
AH00526: Syntax error on line 8 of /etc/apache2/...
...
The Apache error log may have more information.
a2enconf
명령어는 /etc/apache2/conf-available 에 있는 설정 파일의 심링크를 /etc/apache2/conf-enabled 에 자동으로 생성한다.a2enmod
명령어는 /etc/apache2/mods-available 에 있는 모듈의 심링크를 /etc/apache2/mods-available 에 자동으로 생성한다.cd /etc/apache2/conf-available # 설정파일 디렉토리로 이동
vi custom-cache-control.conf # 커스텀 설정 파일 만들기
# custom-cache-control.conf
<FilesMatch "\.(apk|plist|ipa)$">
Header set Cache-Control "no-store"
Header unset ETag
FileETag None
</FilesMatch>
a2enconf custom-cache-control # 추가한 커스텀 설정 파일 사용하기
apachectl configtest # 설정파일 오류 없는지 확인
systemctl restart apache2 # apache 재실행
설정 파일을 추가하고 apachectl configtest 명령어 실행시 아래와 같은 오류 메시지가 출력될 수 있다.
AH00526: Syntax error on line 8 of /etc/apache2/conf-enabled/custom-cache-control.conf:
Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration
Action 'configtest' failed.
The Apache error log may have more information.
headers 모듈이 활성화되어 있지 않아서 그런 것이므로 a2enmod 명령어로 headers 모듈을 활성화해준다.
a2enmod headers
성공적으로 모듈이 활성화가 된 경우 아래와 같이 출력된다.
Enabling module headers.
To activate the new configuration, you need to run:
systemctl restart apache2
다시 설정파일 오류가 없는지 확인한다.
apachectl configtest
Syntax OK # 이렇게 나오면 정상
모듈을 활성화/비활성화 하고나면 apache를 재실행 해줘야 한다.
systemctl restart apache2
.htaccess
파일 추가cd /var/www/html/
vi .htaccess
# 내용은 custom-cache-control.conf 파일과 동일
apachectl configtest # 설정파일 오류 확인