[에러] (13)Permission denied: [client ...] AH00035: access to ... denied ... because search permissions are missing on a component of the path

리눅스/APACHE|2021. 11. 8. 16:23
반응형

아파치 에러 로그

[Mon Nov 08 16:04:03.287735 2021] [core:error] [pid 7206] (13)Permission denied: [client 192.168.220.104:41978] AH00035: access to /test.php denied (filesystem path '/RESTAPI/html/test.php') because search permissions are missing on a component of the path

 

디렉토리와 파일 접근 권한은 있는데 위와 같이 에러로그가 남을 경우 해결 방법입니다.

 

 

점검

/var/log/audit/audit.log 로그 파일을 열어 아래 내용이 출력되었는지 살펴봅니다.

 

type=AVC msg=audit(1636355741.333:1432): avc:  denied  { getattr } for  pid=8010 comm="httpd" path="/RESTAPI/logs/test.php" dev="sda2" ino=9568262 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:default_t:s0 tclass=file permissive=0
type=SYSCALL msg=audit(1636355741.333:1432): arch=c000003e syscall=6 success=no exit=-13 a0=7ffe0fa1c170 a1=7ffe0fa1c050 a2=7ffe0fa1c050 a3=ffffff00 items=0 ppid=8007 pid=8010 auid=4294967295 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) ses=4294967295 comm="httpd" exe="/usr/sbin/httpd" subj=system_u:system_r:httpd_t:s0 key=(null)
type=PROCTITLE msg=audit(1636355741.333:1432): proctitle=2F7573722F7362696E2F6874747064002D44464F524547524F554E44

 

 

해결

# chcon -R -t httpd_sys_content_t /RESTAPI/html

 

반응형

댓글()

httpd 특정 파일명 또는 확장자 로그 (access_log) 남기지 않기

리눅스/APACHE|2021. 7. 1. 10:11
반응형

# vi /etc/httpd/conf/httpd.conf

 

SetEnvifNoCase Request_URI (log.html|png)$ FILE=1  // 추가
CustomLog "logs/access_log" common env=!FILE        // 수정

 

위 예제에서는 log.html 파일 접근이나 png 확장자를 가진파일은 access_log 에 남기지 않습니다.

빨간 글씨를 적절히 수정해 빈번히 발생되는 로그는 기록하지 않을 수 있습니다.

 

수정하였으면 적용을 위해 httpd 를 재시작 합니다.

# systemctl restart httpd

 

 

반응형

댓글()

[에러] (43)Identifier removed: AH00144: couldn't grab the accept mutex

리눅스/APACHE|2021. 5. 24. 15:33
반응형

Apache 2.4.29 에서 mod_ssl 을 설정 후 아래와 같이 로그가 기록되며 apache2 데몬이 종료되는 현상이 발생되었습니다.

[Mon May 24 12:15:45.179136 2021] [mpm_prefork:emerg] [pid 21881] (43)Identifier removed: AH00144: couldn't grab the accept mutex
[Mon May 24 12:15:45.179332 2021] [mpm_prefork:emerg] [pid 21539] (43)Identifier removed: AH00144: couldn't grab the accept mutex
[Mon May 24 12:15:45.179353 2021] [mpm_prefork:emerg] [pid 21555] (43)Identifier removed: AH00144: couldn't grab the accept mutex
[Mon May 24 12:15:45.179370 2021] [mpm_prefork:emerg] [pid 21534] (43)Identifier removed: AH00144: couldn't grab the accept mutex
[Mon May 24 12:15:45.179394 2021] [mpm_prefork:emerg] [pid 21541] (43)Identifier removed: AH00144: couldn't grab the accept mutex
[Mon May 24 12:15:45.179390 2021] [mpm_prefork:emerg] [pid 21537] (43)Identifier removed: AH00144: couldn't grab the accept mutex
[Mon May 24 12:15:45.179414 2021] [mpm_prefork:emerg] [pid 22564] (43)Identifier removed: AH00144: couldn't grab the accept mutex
[Mon May 24 12:15:45.179437 2021] [mpm_prefork:emerg] [pid 21556] (43)Identifier removed: AH00144: couldn't grab the accept mutex
[Mon May 24 12:15:45.196963 2021] [core:alert] [pid 1325] AH00050: Child 21534 returned a Fatal error... Apache is exiting!
[Mon May 24 12:15:45.197000 2021] [:emerg] [pid 1325] AH02818: MPM run failed, exiting

 

이를 해결하기 위해 설정파일의 옵션을 아래의 값으로 활성화 해주면 됩니다.

/etc/apache2/apache2.conf

Mutex posixsem

 

아파치를 재시작하여 적용합니다.

# systemctl restart apache2

 

 

반응형

댓글()

Apache2 구동 에러 : AH00111: Config variable ${APACHE_RUN_DIR} is not defined

리눅스/APACHE|2020. 11. 25. 15:40
반응형

아파치를 구동이 잘 되지 않아 설정 체크를 해보았더니 아래와 같은 에러 메세지가 출력 되었습니다.


root@sysdocu:/root# systemctl restart apache2

Job for apache2.service failed because the control process exited with error code.

See "systemctl status apache2.service" and "journalctl -xe" for details.


root@sysdocu:/root# apache2 -t

[Wed Nov 25 15:34:44.220065 2020] [core:warn] [pid 52764] AH00111: Config variable ${APACHE_RUN_DIR} is not defined

apache2: Syntax error on line 80 of /etc/apache2/apache2.conf: DefaultRuntimeDir must be a valid directory, absolute or relative to ServerRoot


이 경우 아래와 같이 환경 변수 파일을 다시 적용하면 해결이 됩니다.


root@sysdocu:/root# source /etc/apache2/envvars 


root@sysdocu:/root# apache2 -t

Syntax OK


이상이 없으므로 아파치 재시작을 해줍니다.


root@sysdocu:/root# systemctl restart apache2



반응형

댓글()

CentOS 8 에 YUM 으로 APM 설치하기 (특정 확장자에서 PHP 코드 사용 포함)

리눅스/APACHE|2020. 11. 10. 10:25
반응형

OS 환경 패키지 업데이트

# yum -y update


기본 라이브러리 설치

# yum install -y libjpeg* libpng* freetype* gd-* gcc gcc-c++ gdbm-devel libtermcap-devel


아파치 설치

# yum install -y httpd*


마리아DB 설치

# yum install -y mariadb*


PHP 설치

# yum install -y php php-common php-opcache php-cli php-gd php-curl php-mysqlnd


환경 설정

# vi /etc/httpd/conf/httpd.conf


<IfModule dir_module>

    DirectoryIndex index.html index.php

</IfModule>


# vi /etc/php.ini


short_open_tag = On

date.timezone = "Asia/Seoul"


# vi /etc/my.cnf.d/mariadb-server.cnf


[mysqld] 섹션에 아래 내용 추가 (한글이 웹상에서 잘 표시되도록 설정)

character-set-client-handshake=FALSE

collation-server=utf8_general_ci

character-set-server=utf8 


적용

# systemctl restart httpd

# systemctl restart php-fpm

# systemctl restart mysqld


php 코드를 html 파일에서 사용하려면 아래 작업을 추가로 진행 해줍니다.


# vi /etc/httpd/conf.d/php.conf


<IfModule !mod_php5.c>

  <IfModule !mod_php7.c>

    # Enable http authorization headers

    SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1


    <FilesMatch \.(php|phar|html)$>    // 확장자 추가

        SetHandler "proxy:unix:/run/php-fpm/www.sock|fcgi://localhost"

    </FilesMatch>

  </IfModule>

</IfModule> 


# vi /etc/php-fpm.d/www.conf


security.limit_extensions = .php .php3 .php4 .php5 .php7 .html    // 주석 해제 및 확장자 추가

 listen.allowed_clients = 0.0.0.0    // 수정


적용

# systemctl restart httpd

# systemctl restart php-fpm





반응형

댓글()

아파치 설치 에러 libaprutil-1.so: undefined reference to `XML_SetElementHandler collect2: error: ld returned 1 exit status apache make

리눅스/APACHE|2020. 11. 9. 16:55
반응형

아파치 2.4.46 설치 도중 아래와 같은 메세지를 만났습니다.


(make 에러)

libaprutil-1.so: undefined reference to `XML_SetElementHandler 

collect2: error: ld returned 1 exit status apache make


이경우 아래와 같이 조치합니다.


# vi build/config_vars.mk


AP_LIBS 으로 시작되는 행을 찾아서 맨 뒤에 -lexpat 를  추가하고 다시 컴파일 합니다.


# make clean

# make

반응형

댓글()

Error 403, 404 를 특정 html 페이지로 출력하기

리눅스/APACHE|2020. 11. 4. 08:17
반응형

없는 파일이나 접근 불가능한 페이지에 접근할 경우 특정 html 파일을 출력할 수 있습니다.

각각의 사이트 VirtualHost 설정에 아래 내용을 추가 합니다.


ErrorDocument 403 /404.html

ErrorDocument 404 /404.html


그리고 DocumentRoot (소스 최상위 디렉토리) 에 404.html 파일을 만들어 안내하고 싶은 내용으로 채우면 됩니다.

아파치 데몬을 재시작 하여 적용합니다.


# systemctl restart apache2



반응형

댓글()

error 로그에서 favicon.ico 로그 남기지 않기

리눅스/APACHE|2020. 9. 22. 08:06
반응형

httpd.conf 파일에 아래 내용 삽입하고 데몬 재시작 하면 됩니다.



Redirect 404 /favicon.ico


<Location /favicon.ico>

    ErrorDocument 404 "No favicon"

</Location>


반응형

댓글()

Let's encrypt 설치 및 무료 SSL 인증서 발급 받기 (Ubuntu 20.04, 22.04)

리눅스/APACHE|2020. 9. 1. 13:07
반응형

무료 SSL 인증서를 발급받는 방법입니다.

단, 기간은 3개월이며 만료 한 달 전부터 갱신을 할 수 있습니다.

방법은 아래와 같습니다.

 

1. Let's encrypt 설치

 

root@sysdocu:~# apt -y install letsencrypt

 

2. 인증서 발급

 

(단일 도메인 SSL 발급)

root@sysdocu:~# letsencrypt certonly -a webroot --agree-tos -m [이메일] -w [웹소스 디렉토리] -d [SSL 도메인명] --rsa-key-size 4096

 

(다중 도메인 SSL 발급)

root@sysdocu:~# letsencrypt certonly -a webroot --agree-tos -m [이메일] -w [웹소스 디렉토리] -d [SSL 도메인명] -w [웹소스 디렉토리] -d [SSL 발급도메인명] --rsa-key-size 4096

 

이와 같이 실행하면 웹페이지가 정상 접근 가능한 상태일때 인증서가 발급되어 집니다.

아래 디렉토리로 이동하여 인증서 파일을 확인합니다.

 

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/[도메인]/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/[도메인]/privkey.pem

 

3. 인증서 설정

 

실제 인증서는 /etc/letsencrypt/archive/[도메인] 에 있으나, 인증서를 업데이트 할때마다 파일명이 바뀌므로

아래 위치에 있는 심볼록 링크 파일을 virtualhost 설정 항목에 넣어 주어야 자동으로 갱신된 인증서로 연결 가능합니다.

 

<VirtualHost *:443>

DocumentRoot [웹소스 디렉토리]

ServerName [도메인명]:443

...

SSLEngine on

SSLCertificateFile /etc/letsencrypt/live/[도메인명]/cert.pem

SSLCertificateKeyFile /etc/letsencrypt/live/[도메인명]/privkey.pem

SSLCertificateChainFile /etc/letsencrypt/live/[도메인명]/fullchain.pem

</VirtualHost>

 

수정 후 apache2 를 재시작하여 적용 합니다.

 

root@sysdocu:~# systemctl restart apache2

 

 

4. 인증서 갱신

 

root@sysdocu:~# vi /root/ssl-renew.sh

#!/bin/bash
./letsencrypt certonly -a webroot --agree-tos --renew-by-default -w [웹소스 디렉토리] -d [SSL 도메인명] --rsa-key-size 4096
systemctl restart apache2

root@sysdocu:~# chmod 700 /root/ssl-renew.sh

 

두 달에 한 번씩 1일, 16일에 갱신 시도를 하도록 설정 합니다.

 

root@sysdocu:~# echo "01 00 01,16 */2 * root sh /root/ssl-renew.sh" >> /etc/crontab

 

반응형

댓글()

mod_rewrite 특정 파일 또는 디렉토리 제외하고 포워딩 하기

리눅스/APACHE|2019. 7. 25. 17:46
반응형

.htaccess

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/test.html

RewriteCond %{REQUEST_URI} !^/imsi/

RewriteRule ^(.*)$ http://sysdocu.tistory.com/$1 [L,R=301]

 

위 예제에서는 test.html 및 imsi 디렉토리를 제외하고 모두 sysdocu.tistory.com 으로 포워딩 됩니다.

 

 

반응형

댓글()

Ubuntu 에서 Apache 2.4 와 Tomcat 8 (2대) 연동하기

리눅스/APACHE|2019. 6. 12. 13:09
반응형

Apache 서버 : 49.247.214.95

Tomcat 서버 : 49.247.213.105

 

1. Apache 설치 및 설정

(Apache 서버에서)

[root@sysdocu ~]# apt-get -y update

[root@sysdocu ~]# apt-get -y install apache2

[root@sysdocu ~]# apt-get -y install libapache2-mod-jk

[root@sysdocu ~]# vi /etc/apache2/workers.properties

workers.tomcat_home=/usr/share/tomcat8    // Apache 서버에 이런 주소가 없어도 상관 없음
workers.java_home=/usr/lib/jvm/java-8-openjdk-amd64
# Define 1 real worker ajp13
worker.list=tomcat1
# Set properties for tomcat1 (ajp13)
worker.tomcat1.port = 8009
worker.tomcat1.host = 192.168.10.2   // Apache 와 Tomcat 을 하나의 서버로 운영한다면 'localhost' 로 변경
worker.tomcat1.type = ajp13
worker.tomcat1.lbfactor = 20

 

Tomcat 서버가 두 대라면, 아래와 같이 셋팅합니다.

worker.list= tomcat1, tomcat2    // 이름은 임의로 설정
 
worker.tomcat1.type=ajp13
worker.tomcat1.host=톰캣서버 IP
worker.tomcat1.port=8009
worker.tomcat1.lbfactor=1
 
worker.tomcat2.type=ajp13
worker.tomcat2.host=톰캣서버 IP
worker.tomcat2.port=8009
worker.tomcat2.lbfactor=2

 

[root@sysdocu ~]# vi /etc/apache2/mods-available/jk.conf

...(생략)...
JkWorkersFile /etc/apache2/workers.properties
...(생략)...

 

[root@sysdocu ~]# vi /etc/apache2/sites-enabled/000-default.conf

...(생략)...
DocumentRoot /var/www/html
JkMount /*.jsp tomcat1    // jsp 확장자는 tomcat1 서버에서 구동 되도록 설정을 추가 합니다.

...(생략)...

 

[root@sysdocu ~]# /etc/init.d/apache2 restart

 

2. Tomcat 설치 및 설정

(Tomcat 서버에서)

[root@sysdocu ~]# apt-get -y update

[root@sysdocu ~]# apt-get -y install tomcat8

[root@sysdocu ~]# vi /etc/tomcat8/server.xml

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />    // 주석 해제

 

[root@sysdocu ~]# /etc/init.d/tomcat8 restart

 

* Apache 서버에서 접속할 수 있게 iptables 방화벽에서 8009, 8080 포트를 오픈합니다.

 

3. 테스트

(Tomcat 서버에서)

[root@sysdocu ~]# vi /var/lib/tomcat8/webapps/ROOT/test.jsp

<%
String str = request.getParameter("name");
if(str == null)
{ str = "JSP"; }
%>
Hello, <%= str %>!!!

 

(PC 웹브라우저에서)

웹브라우저에서 아래와 같이 접속 테스트를 합니다.

 

http://192.168.10.2                      // 기본 아파치 index.html 페이지가 뜹니다.

http://192.168.10.2/test.jsp    // 톰캣 서버에서 생성한 test.jsp 페이지가 뜹니다.

 

반응형

댓글()