centos7과 nginx에서 정적 파일 제공
Post

centos7과 nginx에서 정적 파일 제공

아래와 같이 nginx가 설정되어 있다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
server {
    listen 80 default_server;
    server_name localhost;

    location / {
        proxy_pass http://localhost:8000;
    }

    location /static {
        alias /home/jhpark/sites/www.jrr.kr/static;
    }

    error_page 404 /404.html;
    location = /40x.html {
    }

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    }
}

이 경우 static 파일 제공 디렉토리(/home/jhpark/sites/www.jrr.kr/static)부터 부터 최상위 디렉토리(/) 까지 차례 대로 모두 실행 권한이 있어야 한다.

1
2
3
4
5
6
drwxr-xr-x root   root   /
drwxr-xr-x root   root   home
drwx--x--x jhpark jhpark jhpark
drwxr-xr-x jhpark jhpark sites
drwxr-xr-x jhpark jhpark www.jrr.kr
drwxr-xr-x jhpark jhpark static

이와는 별도로 selinux가 활성화 되어 있을 경우 (getenforce 명령의 결과 Enforcing가 출력될 경우)

1
sudo chcon -Rt httpd_sys_content_t /home/jhpark/sites/www.jrr.kr/static

을 해주어야 한다.

아니면 아예 selinux를 비활성해 해 주어야 한다.

1
setenforce 0