모든 파일에 대해 Nginx 403 금지
CentOS 5 상자에 PHP-FPM과 함께 nginx를 설치했지만 PHP 여부에 관계없이 내 파일을 제공하기 위해 고심하고 있습니다.Nginx가 www-data : www-data로 실행 중이며 기본 "EPEL의 nginx에 오신 것을 환영합니다"사이트 (644 권한이있는 root : root 소유)가 정상적으로로드됩니다.nginx 구성 파일에는
/etc/nginx/sites-enabled/*.conf에
대한 include 지시문 이 있으며 구성 파일
example.com.conf
가 있습니다.
server {
listen 80;
Virtual Host Name
server_name www.example.com example.com;
location / {
root /home/demo/sites/example.com/public_html;
index index.php index.htm index.html;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param PATH_INFO $fastcgi_scriptname;
fastcgi_param scriptFILENAME /home/demo/sites/example.com/public_html$fastcgi_scriptname;
include fastcgi_params;
}
}
2777 개의 파일 권한이있는 www-data : www-data가 public_html을 소유하고 있지만이 사이트는 어떤 콘텐츠도 제공하지 않습니다.
[error] 4167#0: *4 open() "/home/demo/sites/example.com/public_html/index.html" failed (13: Permission denied), client: XX.XXX.XXX.XX, server: www.example.com, request: "GET /index.html HTTP/1.1", host: "www.example.com"
사용자가 nginx에서 403을 얻는 다른 게시물을 많이 발견했지만 루비 / Passenger (이전에는 실제로 성공했습니다)를 사용하여 더 복잡한 설정이 포함되거나 업스트림 PHP가 발생했을 때만 오류가 발생하는 것을 보았습니다 -FPM이 관여하므로 도움이 거의없는 것 같습니다.내가 여기서 어리석은 짓을 했습니까?
간과되는 권한 요구 사항 중 하나는 사용자가 파일의 모든 상위 디렉토리에 해당 파일에 액세스하기위한 x 권한이 필요하다는 것입니다. www-data x 액세스에 대한 /, / home, / home / demo 등에 대한 권한을 확인하십시오. 내 생각에 / home은 아마 770이고 www-data는 그것을 통해 어떤 하위 디렉토리에 도달 할 수 없습니다. 그렇다면 chmod o + x / home (또는 요청을 거부하는 디렉토리)을 시도하십시오.편집 : 경로에 대한 모든 권한을 쉽게 표시하려면
namei -om /path/to/check
permission denied
상위 폴더의 권한을 확인한 후에도 여전히 표시되면
SELinux가
액세스를 제한 하는 것일 수 있습니다 .SELinux가 실행 중인지 확인하려면 다음을 수행하십시오.
# getenforce
다음에 재부팅 할 때까지 SELinux를 비활성화하려면 :
# setenforce Permissive
Nginx를 다시 시작하고 문제가 지속되는지 확인하십시오. nginx가 www 디렉토리를 제공 할 수있게하려면 (이를 테스트하기 전에 SELinux를 다시 켜십시오 (예 :)
setenforce Enforcing
)
# chcon -Rt httpd_sys_content_t /path/to/www
자세한 내용은
내 답변 을 참조하십시오
사용자 설정을 추가하여이 문제를 해결했습니다.nginx.conf에서
worker_processes 4;
user username;
리눅스 사용자 이름으로 '사용자 이름'을 변경하십시오.
이 오류가 발생하여 마침내 아래 명령으로 해결했습니다.
restorecon -r /var/www/html
한 장소에서 다른 장소로 무언가를 측정 할 때 문제가 발생합니다. 이동시 원본의 selinux 컨텍스트를 유지하므로 / home 또는 / tmp에서 무언가를 untar하면 해당 위치와 일치하는 selinux 컨텍스트가 제공됩니다. 이제 / var / www / html로 mv를 지정하고 / tmp 또는 / home에 속하는 컨텍스트를 취하고 정책에 의해 httpd가 해당 파일에 액세스 할 수 없습니다.mv 대신 cp 파일을 사용하면 selinux 컨텍스트는 원래 위치가 아니라 복사하는 위치에 따라 지정됩니다. restorecon을 실행하면 컨텍스트가 기본값으로 돌아가고 수정됩니다.
나는 다른 경우를 시도했으며 소유자가 nginx (
chown -R nginx:nginx "/var/www/myfolder"
) 로 설정되었을 때만 예상대로 작동하기 시작했습니다.
Old question, but I had the same issue. I tried every answer above, nothing worked. What fixed it for me though was removing the domain, and adding it again. I'm using Plesk, and I installed Nginx AFTER the domain was already there.
Did a local backup to /var/www/backups first though. So I could easily copy back the files.
Strange problem....
I dug myself into a slight variant on this problem by mistakenly running the setfacl
command. I ran:
sudo setfacl -m user:nginx:r /home/foo/bar
I abandoned this route in favor of adding nginx
to the foo
group, but that custom ACL was foiling nginx's attempts to access the file. I cleared it by running:
sudo setfacl -b /home/foo/bar
And then nginx was able to access the files.
We had the same issue, using Plesk Onyx 17. Instead of messing up with rights etc., solution was to add nginx user into psacln group, in which all the other domain owners (users) were:
usermod -aG psacln nginx
Now nginx has rights to access .htaccess or any other file necessary to properly show the content.
On the other hand, also make sure that Apache is in psaserv group, to serve static content:
usermod -aG psaserv apache
And don't forget to restart both Apache and Nginx in Plesk after! (and reload pages with Ctrl-F5)
If you are using PHP, make sure the index
NGINX directive in the server block contains a index.php:
index index.php index.html;
For more info checkout the index directive in the official documentation.
If you're using SELinux, just type:
sudo chcon -v -R --type=httpd_sys_content_t /path/to/www/
This will fix permission issue.
I was facing the same issue but above solutions did not help.
So, after lot of struggle I found out that sestatus was set to enforce which blocks all the ports and by setting it to permissive all the issues were resolved.
sudo setenforce 0
Hope this helps someone like me.
참고URL : https://stackoverflow.com/questions/6795350/nginx-403-forbidden-for-all-files
'programing' 카테고리의 다른 글
삭제하기 전에 확인 메시지를 표시하는 방법은 무엇입니까? (0) | 2020.05.18 |
---|---|
삼항 또는 삼항? (0) | 2020.05.18 |
상점을 여는 데 사용 된 모델이 상점을 만드는 데 사용 된 모델과 호환되지 않습니다 (0) | 2020.05.18 |
Android SDK 용 빠른 비트 맵 흐림 (0) | 2020.05.18 |
다른 블록을 시작하기 전에 두 개의 비동기 블록이 실행될 때까지 대기 (0) | 2020.05.18 |