
Ich verwende Nginx mit Puma (für eine Rails-Anwendung) unter CentOS 7. Ich bin verwirrt, wie ich die Berechtigungen für einen Datei-Upload einrichte. Wenn ich derzeit versuche, eine Datei hochzuladen (ein mehrteiliges Formular absende), erhalte ich den folgenden Fehler im Nginx-Fehlerprotokoll
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"
Ich versuche, alles als „Rails“-Benutzer zum Laufen zu bringen. Unten sind meine Nginx- und Puma-Prozesse
[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
und unten sind die Berechtigungen für das problematische Verzeichnis. Was muss ich sonst noch einstellen, damit dies funktioniert?
[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
Antwort1
Sie führen nginx als der genannte Benutzer aus rails
(was ungewöhnlich ist).
Aber eines Ihrer Verzeichnisse, /var/lib/nginx/tmp
, gehört dem nicht existierenden Benutzer 755.
Der übliche Grund hierfür ist die versehentliche Eingabe chown
von chmod
.
Sie sollten das Problem beheben können, indem Sie den Besitz dieses Verzeichnisses korrigieren.
chown rails /var/lib/nginx/tmp
Übrigens, Sie scheinen auch SELinux deaktiviert zu haben. Sie solltenrepariere daszum frühestmöglichen Zeitpunkt.
Antwort2
Sie können sehen, /var/lib/nginx/tmp
dass es dem Benutzer 755 gehört. Wahrscheinlich haben Sie den falschen Befehl verwendet: chown
statt chmod
.
So beheben Sie das Problem:
chmod 755 /var/lib/nginx/tmp
chown rails /var/lib/nginx/tmp