Apache 같은 중요 인프라를 직접 소스를 컴파일해서 사용하는 방법도 있으나 직접 소스를 컴파일 하는 방법은 버그나 취약점도 직접 대응 해야하는 문제가 생겨 패키지 설치를 더 권장한다고 합니다.
설치 후 잠시 설정파일과 로그 파일이 위치한 곳을 확인 해보겠습니다.
경로는 /etc/httpd 입니다
주요 디렉토리 설명
conf: 웹 서버의 주요 설정 파일인 httpd.conf, MIME 형식을 지정하기 위한 파일인 magic 파일이 있는 곳
conf.d: 아파치의 주요설정을 분리 해서 저장 하는 곳, httpd.conf 설정내용을 분리하여 이곳에 저장하면, httpd.conf 파일에서 불러와서 사용하게 됩니다. httpd.conf 파일 맨 마지막에 IncludeOptional conf.d/*.conf 구문이 있습니다.
/var/www/html 경로의 디렉토리에 들어가시면 파일이 존재하지 않습니다. 여기에 vi 에디터로 index.html 파일을 생성하고 저장하신 후 다시 사이트로 들어가시면 자신이 저장한 index.html파일이 화면에 뿌려지는 것을 확인하실 수 있습니다.
httpd.conf 수정으로 기본 home 디렉토리의 경로를 변경시 403 Forbidden You don’t have permission to access / on this server. 접근 권한 에러가 나타날 수 있습니다. SELinux 방화벽 해제를 하고 접근이 되는지 확인해 볼 수 있습니다.
1
$ setenforce 0
httpd.conf 파일 수정
1 2 3 4 5 6 7 8 9 10 11 12 13
# If you wish httpd to run as a different user or group, you must run # httpd as root initially and it will switch. # // 변경 전 # User/Group: The name (or #number) of the user/group to run httpd as. # It is usually good practice to create a dedicated user and group for # running httpd, as with most system services. # User apache Group apache
# // 변경 후 User nobody Group nobody
1 2 3 4 5 6 7 8 9 10 11
# ServerName gives the name and port that the server uses to identify itself. # This can often be determined automatically, but we recommend you specify # it explicitly to prevent problems during startup. # # If your host doesn't have a registered DNS name, enter its IP address here. # // 변경 전 #ServerName www.example.com:80
# // 변경 후 ServerName {서버아이피주소}:80
1 2 3 4 5 6 7 8 9 10 11 12 13
# Relax access to content within /var/www. # // 변경 전 <Directory "/var/www"> AllowOverride None # Allow open access: Require all granted </Directory>
# // 변경 후 <Directory "/"> AllowOverride None Require all granted </Directory>
# Further relax access to the default document root: # // 변경 전 <Directory "/var/www/html"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.4/mod/core.html#options # for more information. # Options Indexes FollowSymLinks
# # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride None
# # Controls who can get stuff from this server. # Require all granted </Directory>
# // 변경 후 <Directory "/var/www/html"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.4/mod/core.html#options # for more information. # Options Indexes FollowSymLinks
# # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride None
# # Controls who can get stuff from this server. # Order allow,deny Allow from all </Directory>
1 2 3 4 5 6 7 8 9 10 11
# DirectoryIndex: sets the file that Apache will serve if a directory # is requested. # // 변경 전 <IfModule dir_module> DirectoryIndex index.html </IfModule>
# // 변경 후 <IfModule dir_module> DirectoryIndex index.html index.html.var index.php index.u </IfModule>
1 2 3 4 5 6 7 8 9 10 11 12
# The following lines prevent .htaccess and .htpasswd files from being # viewed by Web clients. # // 변경 전 <Files ".ht*"> Require all denied </Files>
# // 변경 후 <Files ~ "^\.ht"> Order allow,deny Deny from all </Files>
# "/var/www/cgi-bin" should be changed to whatever your ScriptAliased # CGI directory exists, if you have that configured. # // 변경 전 <Directory "/var/www/cgi-bin"> AllowOverride None Options None Require all granted </Directory>
<IfModule mime_module> # # TypesConfig points to the file containing the list of mappings from # filename extension to MIME-type. # TypesConfig /etc/mime.types
# # AddType allows you to add to or override the MIME configuration # file specified in TypesConfig for specific file types. # #AddType application/x-gzip .tgz # # AddEncoding allows you to have certain browsers uncompress # information on the fly. Note: Not all browsers support this. # #AddEncoding x-compress .Z #AddEncoding x-gzip .gz .tgz # # If the AddEncoding directives above are commented-out, then you # probably should define those extensions to indicate media types: # AddType application/x-compress .Z AddType application/x-gzip .gz .tgz
# # AddHandler allows you to map certain file extensions to "handlers": # actions unrelated to filetype. These can be either built into the server # or added with the Action directive (see below) # # To use CGI scripts outside of ScriptAliased directories: # (You will also need to add "ExecCGI" to the "Options" directive.) # #AddHandler cgi-script .cgi
# For type maps (negotiated resources): #AddHandler type-map var
# # Filters allow you to process content before it is sent to the client. # # To parse .shtml files for server-side includes (SSI): # (You will also need to add "Includes" to the "Options" directive.) # AddType text/html .shtml AddOutputFilter INCLUDES .shtml </IfModule>
# // 변경 후 <Directory "/var/www/cgi-bin"> AllowOverride None Options None Require all granted </Directory>
<IfModule mime_module> # # TypesConfig points to the file containing the list of mappings from # filename extension to MIME-type. # TypesConfig /etc/mime.types
# # AddType allows you to add to or override the MIME configuration # file specified in TypesConfig for specific file types. # #AddType application/x-gzip .tgz AddType application/x-httpd-php .php .html .htm .inc AddType application/x-httpd-php-source .phps
# # AddEncoding allows you to have certain browsers uncompress # information on the fly. Note: Not all browsers support this. # #AddEncoding x-compress .Z #AddEncoding x-gzip .gz .tgz # # If the AddEncoding directives above are commented-out, then you # probably should define those extensions to indicate media types: # AddType application/x-compress .Z AddType application/x-gzip .gz .tgz
# # AddHandler allows you to map certain file extensions to "handlers": # actions unrelated to filetype. These can be either built into the server # or added with the Action directive (see below) # # To use CGI scripts outside of ScriptAliased directories: # (You will also need to add "ExecCGI" to the "Options" directive.) # #AddHandler cgi-script .cgi AddHandler php7-script .php .u
# For type maps (negotiated resources): AddHandler type-map var
# # Filters allow you to process content before it is sent to the client. # # To parse .shtml files for server-side includes (SSI): # (You will also need to add "Includes" to the "Options" directive.) # AddType text/html .shtml AddOutputFilter INCLUDES .shtml </IfModule>
httpd.conf 파일 수정 후 에러가 발생하면 httpd -t 명령어로 httpd.conf 몇째 줄이 틀렸는지 확인 해 볼 수 있습니다.
1 2
$ cd /etc/httpd/conf/ // httpd.conf 파일이 있는 경로로 이동 $ httpd -t
가상 호스트
각각의 도메인마다 다른 서비스를 하고 싶을때 아파치의 VirtualHost를 사용하면 편리합니다.
1 2 3 4 5 6 7
# Supplemental configuration # # Load config files in the "/etc/httpd/conf.d" directory, if any. IncludeOptional conf.d/*.conf
# 가상호스트 .conf 파일 경로 추가 Include /etc/httpd/conf/extra/httpd-vhosts.conf
etc/httpd/conf/extra 디렉토리안에 httpd-vhosts.conf 파일을 생성 후 아래와 같이 작성합니다.