태그 보관물: Apache

아파치 웹서버 정보 숨기기

  • 기본 설정된 아파치로 웹서비스를 하게 될 경우 HTTP헤더 또는 에러페이지에 웹서버의 정보가 함께 전달 됩니다.
  • 웹서버의 상세 버전, OS의 정보 등 불필요한 정보를 공개하여 취약점을 노출 시킬 수 있으므로 숨김 처리가 필요합니다.
[test@localhost ~]$ curl --head www.sierracloud.kro.kr
HTTP/1.1 302 Found
Date: Fri, 05 Mar 2021 02:21:54 GMT
Server: Apache/2.4.x (CentOS) OpenSSL/1.0.x PHP/7.2.x
// 웹서버/OS 버전외에도 PHP버전까지 노출되고 있습니다.
# httpd.conf 또는 httpd-default.conf 아래 설정 추가
ServerTokens Prod
ServerSignature Off

// 아파치 재기동
# systemctl restart httpd
키워드제공 정보예문
Prod웹 서버 종류Apache
Min웹 서버 버전Apache/2.2.3
OS웹 서버 버전 + 운영체제Apache/2.2.3 (CentOS)
Full웹 서버의 모든 정보Apache/2.2.3 (CentOS) DAV/2 PHP/5.16
ServerTokens 지시자 옵션
[test@localhost ~]$ curl --head www.sierracloud.kro.kr
HTTP/1.1 302 Found
Date: Fri, 05 Mar 2021 02:26:10 GMT
Server: Apache
// 웹서버 종류만 표시

WordPress 설치(Apache base)

아파치 기반 워드프레스 설치를 진행 해보겠습니다.

설치 환경은 아래와 같습니다.

  • CentOS 7 64bit
  • Apache 2.4
  • php 7.2
  • MariaDB 10.3

1. Apache 설치

1.1 패키지 설치(ssl 설정을 위해 mod_ssl 설치)

# yum install httpd httpd-devel mod_ssl -y

1.2 httpd.conf 설정

<VirtualHost *:80>
  RewriteEngine On
  RewriteCond %{HTTPS} !=on
  RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
  DocumentRoot /app/doc/wordpress
  ServerName www.sierracloud.kro.kr
  ServerAlias www.sierracloud.kro.kr
</VirtualHost>

<VirtualHost *:443>
  SSLEngine on
  SSLCertificateFile /etc/pki/tls/certs/ca.crt
  SSLCertificateKeyFile /etc/pki/tls/private/ca.key
  DocumentRoot /app/doc/wordpress
  ServerName www.sierracloud.kro.kr
  ServerAlias www.sierracloud.kro.kr
</VirtualHost>

1.3 ssl.conf (openssl 설정 방법은 https://www.sierracloud.kro.kr/https-%ea%b5%ac%ec%84%b1 참고)

SSLCertificateFile /etc/pki/tls/certs/ca.crt
SSLCertificateKeyFile /etc/pki/tls/private/ca.key

2. php 설치

# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
# yum install mod_php72w php72w-cli -y
# yum install php72w-bcmath php72w-gd php72w-mbstring php72w-mysqlnd php72w-pear php72w-xml php72w-xmlrpc php72w-process -y

// 설치 버전 확인
# php-v

3. MariaDB 설치

3.1 패키지 설치 ( https://www.sierracloud.kro.kr/mariadb-10-3-%ec%84%a4%ec%b9%98 참고 )

3.2 wordpress 용 계정 및 db 생성

# mysql -u root -p password

> CREATE DATABASE wordpress CHARACTER SET utf8 COLLATE utf8_bin;
> GRANT ALL PRIVILEGES on wordpress.* to wordpress@'localhost' IDENTIFIED BY 'password';
> FLUSH PRIVILEGES;

4. WordPress 설치

4.1 패키지 설치

# wget https://wordpress.org/latest.tar.gz
# tar zxvf latest.tar.gz

# mv wordpress /app/doc/
# mkdir /app/doc/wordpress/wp-content/uploads
# chown -R apache:apache /app/doc/wordpress
# chmod -R 755 /app/doc/wordpress

# cd /app/doc/wordpress
# mv wp-config-sample.php wp-config.php

4.2 DB정보 적용

# vi wp-config.php

define('DB_NAME', 'wordpress');
/** MySQL database username */
define('DB_USER', 'wordpress');
/** MySQL database password */
define('DB_PASSWORD', 'password');
/** MySQL hostname */
define('DB_HOST', 'localhost');

4.3 Salt 설정 ( https://api.wordpress.org/secret-key/1.1/salt 접속하여 출력된 텍스트 복사 )

#vi wp-config.php

// 아래 문단을 주석처리 또는 삭제 후 복사한 내용을 붙혀넣기
define( 'AUTH_KEY',         'put your unique phrase here' );
define( 'SECURE_AUTH_KEY',  'put your unique phrase here' );
define( 'LOGGED_IN_KEY',    'put your unique phrase here' );
define( 'NONCE_KEY',        'put your unique phrase here' );
define( 'AUTH_SALT',        'put your unique phrase here' );
define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
define( 'LOGGED_IN_SALT',   'put your unique phrase here' );
define( 'NONCE_SALT',       'put your unique phrase here' );

5. 아파치 시작

# systemctl enable httpd
# systemctl start httpd

6. 서버의 IP 또는 URL에 브라우저 정상 접속 확인

아파치 https 구성

아파치 https 구성을 위한 mod ssl 모듈 설치 및 openssl 키구성 과정 예시 입니다.

※ CentOS 6.x 기준으로 작성 되었던 내용입니다. 그리고 아파치를 컴파일로 설치했을 경우 mod_ssl도 다시 컴파일로 설치를 진행해야 합니다.

  • mod_ssl, openssl 선설치
// 설치 여부 확인
# rpm -qa | grep -E "mod_ssl|openssl"

# yum install mod_ssl openssl -y
  • self-signed certificate 생성
// 개인키 생성
# openssl genrsa -out ca.key 1024

// CSR(Certificate Signing Request) 생성
# openssl req -new -key ca.key -out ca.csr
// 국가/주(도)/시/사명//domain(hostname)/// 영문으로 각 순서에 입력

// Self Signed Key 생성
# openssl x509 -req -days 3650 -in ca.csr -signkey ca.key -out ca.crt

// 생성키 복사 처리
# cp ca.crt /etc/pki/tls/certs/
# cp ca.key /etc/pki/tls/private/ca.key
# cp ca.csr /etc/pki/tls/private/ca.csr

※ selinux 인해 삭제시 복구
# restorecon -RvF /etc/pki
  • ssl용 config 수정
# /etc/httpd/conf.d/ssl.conf 수정
#경로 및 파일명 수정
SSLCertificateFile /etc/pki/tls/certs/ca.crt
SSLCertificateKeyFile /etc/pki/tls/private/ca.key
  • httpd config 수정
# /etc/httpd/conf/httpd.conf에 추가
NameVirtualHost *:443 #2.4버전에서는 삭제
<VirtualHost *:443>
  SSLEngine on
  SSLCertificateFile /etc/pki/tls/certs/ca.crt
  SSLCertificateKeyFile /etc/pki/tls/private/ca.key
  ServerAdmin hello.co.kr #인증서 생성 과정에서 설정해준 사용자명 혹은 서버 호스트명은 이곳에 똑같이 적어준다
  DocumentRoot /var/www/html
  ServerName hello.co.kr #인증서 생성 과정에서 설정해준 사용자명 혹은 서버 호스트명은 이곳에 똑같이 적어준다
  ErrorLog logs/ssl_starkapin_com_error_log
  CustomLog logs/ssl_starkapin_com_error_log common
</VirtualHost>

# 페이지 리다이렉트
# mod_rewirte 모듈 활성화 필요
# /etc/httpd/conf/httpd.conf 수정
<VirtualHost *:80>
  RewriteEngine On
  RewriteCond %{HTTPS} !=on
  RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
</VirtualHost>
  • 서비스 재시작
// CentOS 6.x
# service httpd restart

// CentOS 7.x
#systemctl restart httpd
  • 정상 구동 확인
// 80, 443포트 리슨 확인
# netstat -ntlp

// 브라우저 통해 실제 http 접속후 https로 리다이렉션 여부 확인