CenotOS 7 최소 설치가 포함된 새로운 VM이 있습니다.
내가 원하는 것은 .NET 디렉토리의 정적 파일을 제공하도록 Nginx를 구성하는 것입니다 localhost:80
.
내 디렉토리는 입니다 /home/kenny/projects/kcrypt/dist/
.
내 내용은 다음과 같습니다 /etc/nginx/nginx.conf
.
# this is set to root in order to rule out
# any permission related issues.
user root;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
server {
listen 80 default_server;
listen [::]:80 default_server;
root /home/kenny/projects/kcrypt/dist/;
index index.html;
location / {
}
}
}
실행하면 curl http://localhost
다음과 같은 응답을 받습니다.
<html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.12.2</center>
</body>
</html>
나는 내가 생각할 수 있는 모든 디렉토리에 모든 종류의 권한을 부여하려고 노력했습니다.
결국 Nginx를 루트로 실행하도록 구성했습니다.
이미 여러 번 OS를 재설치했는데 제대로 작동하지 않습니다.
추신
이것이 내가 찾은 것입니다/var/log/nginx/error.log
2018/02/27 21:33:19 [error] 15689#0: *1 open() "/home/kenny/projects/kcrypt/dist/index.html" failed (13: Permission denied), client: ::1, server: , request: "GET / HTTP/1.1", host: "localhost"
2018/02/27 21:33:35 [error] 15690#0: *2 open() "/home/kenny/projects/kcrypt/dist/index.html" failed (13: Permission denied), client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/02/27 21:33:38 [error] 15690#0: *3 open() "/home/kenny/projects/kcrypt/dist/index.html" failed (13: Permission denied), client: ::1, server: , request: "GET / HTTP/1.1", host: "localhost"
원하는 것을 얻지 못했습니다... 가능한 모든 권한을 부여했습니다.
이것이 루트 디렉토리에 있는 것입니다:
[root@vm3 dist]# ll
total 368K
drwxrwxrwx. 2 root root 98 Feb 26 23:16 .
drwxrwxrwx. 6 root root 234 Feb 27 21:26 ..
-rwxrwxrwx. 1 root root 1.2K Feb 26 23:16 favicon.ico
-rwxrwxrwx. 1 root root 1.7K Feb 26 23:16 index.html
-rwxrwxrwx. 1 root root 175K Feb 26 22:53 index.js
-rwxrwxrwx. 1 root root 297 Feb 26 23:16 manifest.json
-rwxrwxrwx. 1 root root 179K Feb 26 22:53 styles.css
추신 2
정적 파일을 에 넣으려고 했지만 /var/www/kcrypt/dist/
결과가 없습니다.
여전히 동일한 오류 메시지가 나타납니다.
2018/02/27 23:18:11 [error] 16157#0: *1 open() "/var/www/kcrypt/dist/index.html" failed (13: Permission denied), client: ::1, server: , request: "GET / HTTP/1.1", host: "localhost"
2018/02/27 23:20:58 [error] 16535#0: *1 open() "/var/www/kcrypt/dist/index.html" failed (13: Permission denied), client: ::1, server: , request: "GET / HTTP/1.1", host: "localhost"
2018/02/27 23:21:30 [error] 16564#0: *1 open() "/var/www/kcrypt/dist/index.html" failed (13: Permission denied), client: ::1, server: , request: "GET / HTTP/1.1", host: "localhost"
답변1
시스템에 SELinux가 활성화되어 있습니다. 기본적으로 SELinux는 웹 서버가 사용자의 홈 디렉터리에 있는 파일을 읽는 것을 허용하지 않습니다. 웹 제공에 활성화된 디렉터리는 /var/www
(시스템 패키지가 파일을 저장하는 위치) 및 /srv/www
(사용자가 프로덕션에서 파일을 배치할 것으로 예상되는 위치)입니다.
홈 디렉터리에서 파일을 제공해야 하는 경우 SELinux 부울을 설정하면 httpd_read_user_content
해당 파일을 읽을 수 있습니다.
setsebool -P httpd_read_user_content 1
SELinux는 웹 서버가 다음을 허용하지 않는다는 점을 명심하십시오.쓰다사용자 홈 디렉토리에 있습니다. 이것이 필요한 경우 웹 콘텐츠를 다른 곳에 배치해야 합니다.적절한 디렉토리를 쓰기 가능하게 만드세요.
또한 SELinux가 작동한다는 점을 명심하십시오.게다가일반 UNIX 권한이 있으므로 관련 파일과 디렉터리에는 특정 사용 사례에 관계없이 적절한 소유권과 권한도 있어야 합니다.