
我在 CentOS 7 上使用 Nginx 和 Puma(用於 Rails 應用程式)。目前,當我嘗試上傳文件(提交多部分錶單)時,我在 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"
我試圖讓一切以“rails”用戶身份運行。下面是我的 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
您可以看到由/var/lib/nginx/tmp
使用者 755 擁有。chown
chmod
要解決此問題:
chmod 755 /var/lib/nginx/tmp
chown rails /var/lib/nginx/tmp