여러 부분으로 구성된 양식 제출을 허용하도록 nginx 권한을 어떻게 설정합니까?

여러 부분으로 구성된 양식 제출을 허용하도록 nginx 권한을 어떻게 설정합니까?

저는 CentOS 7에서 Puma(Rails 애플리케이션용)와 함께 Nginx를 사용하고 있습니다. 파일 업로드에 대한 권한을 설정하는 방법이 혼란스럽습니다. 현재 파일을 업로드하려고 하면(여러 부분으로 구성된 양식 제출) nginx 오류 로그에 다음 오류가 표시됩니다.

2018/02/28 16:35:48 [crit] 31241#0: *148 open() "/var/lib/nginx/tmp/client_body/0000000006" failed (13: Permission denied), client: 96.92.233.165, server: example.com, request: "POST /people HTTP/1.1", host: "example.com", referrer: "http://example.com/people/new"

나는 "레일" 사용자로 모든 것을 실행하려고 노력하고 있습니다. 다음은 내 nginx 및 puma 프로세스입니다.

[root@server /]# ps -elf | grep nginx
0 S root       944   920  0  80   0 -  2249 pipe_w 16:38 pts/1    00:00:00 grep --color=auto nginx
1 S root     31238     1  0  80   0 - 30712 rt_sig 15:06 ?        00:00:00 nginx: master process /usr/sbin/nginx
5 S rails    31239 31238  0  80   0 - 30843 ep_pol 15:06 ?        00:00:00 nginx: worker process
5 S rails    31240 31238  0  80   0 - 30843 ep_pol 15:06 ?        00:00:00 nginx: worker process
5 S rails    31241 31238  0  80   0 - 30843 ep_pol 15:06 ?        00:00:00 nginx: worker process
5 S rails    31242 31238  0  80   0 - 30843 ep_pol 15:06 ?        00:00:00 nginx: worker process
[root@server /]# ps -elf | grep puma
1 S rails      582     1  0  80   0 - 135430 poll_s 16:19 ?       00:00:00 puma 3.11.2 (tcp://0.0.0.0:3000,unix:///home/rails/scale_production/shared/sockets/puma.sock) [scale_production]
1 S rails      590   582  0  80   0 - 286725 futex_ 16:19 ?       00:00:02 puma: cluster worker 0: 582 [scale_production]
1 S rails      594   582  0  80   0 - 287282 futex_ 16:19 ?       00:00:03 puma: cluster worker 1: 582 [scale_production]
1 S rails      596   582  0  80   0 - 287255 futex_ 16:19 ?       00:00:02 puma: cluster worker 2: 582 [scale_production]
1 S rails      599   582  0  80   0 - 286939 futex_ 16:19 ?       00:00:02 puma: cluster worker 3: 582 [scale_production]
0 S root       946   920  0  80   0 -  2250 pipe_w 16:38 pts/1    00:00:00 grep --color=auto puma

아래는 문제가 있는 디렉토리에 대한 권한입니다. 이것이 작동하려면 또 무엇을 설정해야 합니까?

[root@server /]# ls -al /var/lib/nginx
total 12
drwx------  3  755 rails 4096 Feb 24 14:33 .
drwxr-xr-x 23 root root  4096 Feb 24 14:33 ..
drwx------  7  755 rails 4096 Feb 24 15:06 tmp
[root@server /]# ls -al /var/lib/nginx/tmp/client_body
total 8
drwx------ 2 rails rails 4096 Feb 24 15:06 .
drwx------ 7   755 rails 4096 Feb 24 15:06 ..
[root@server /]# ls -al /var/lib/nginx/tmp
total 28
drwx------ 7   755 rails 4096 Feb 24 15:06 .
drwx------ 3   755 rails 4096 Feb 24 14:33 ..
drwx------ 2 rails rails 4096 Feb 24 15:06 client_body
drwx------ 2 rails rails 4096 Feb 24 15:06 fastcgi
drwx------ 2 rails rails 4096 Feb 24 15:06 proxy
drwx------ 2 rails rails 4096 Feb 24 15:06 scgi
drwx------ 2 rails rails 4096 Feb 24 15:06 uwsgi

답변1

귀하는 이름이 지정된 사용자로 nginx를 실행하고 있습니다 rails(이것은 특이한 현상입니다).

그러나 귀하의 디렉터리 중 하나인 은(는 /var/lib/nginx/tmp) 존재하지 않는 사용자 755의 소유입니다.

이런 일이 발생하는 일반적인 이유는 을 chown의미할 때 실수로 입력했기 때문입니다 chmod.

이 디렉토리의 소유권을 수정하여 문제를 해결할 수 있습니다.

chown rails /var/lib/nginx/tmp

그런데, SELinux도 비활성화한 것 같습니다. 당신은해야그걸 고쳐가장 빠른 기회에.

답변2

을(를) 사용자 755가 소유한 것을 볼 수 있습니다 . 아마도 . 대신 /var/lib/nginx/tmp잘못된 명령을 사용했을 것입니다 .chownchmod

이 문제를 해결하려면:

chmod 755 /var/lib/nginx/tmp
chown rails /var/lib/nginx/tmp

관련 정보