#nginx
Вопрос:
nginx version: nginx/1.19.0
Моя конф. nginx-это /etc/nginx/nginx.conf
user root; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"' ' query_string=$query_string' ' port=$upstream_http_port' ' b=$arg_b'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; server { listen 10001; server_name test1; location / { root /home/static/; index index.html; } } }
мой html-файл является
$ cat /home/static/index.html hello
-rw-r--r--. 1 root root 6 2021-10-07 05:38:24 static/index.html
когда я запускаю руководство nginx,это работа .
$ nginx amp;amp; curl localhost:10001 hello
но когда я начинаю с systemctl
$ systemctl start nginx amp;amp; curl localhost:10001 lt;htmlgt; lt;headgt;lt;titlegt;403 Forbiddenlt;/titlegt;lt;/headgt; lt;bodygt; lt;centergt;lt;h1gt;403 Forbiddenlt;/h1gt;lt;/centergt; lt;hrgt;lt;centergt;nginx/1.19.0lt;/centergt; lt;/bodygt; lt;/htmlgt;
статус nginx.service выглядит следующим образом
$ systemctl status nginx ● nginx.service - nginx - high performance web server Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled) Active: active (running) since Thu 2021-10-07 07:34:00 CST; 1min 23s ago Docs: http://nginx.org/en/docs/ Process: 13951 ExecStop=/bin/sh -c /bin/kill -s TERM $(/bin/cat /var/run/nginx.pid) (code=exited, status=1/FAILURE) Process: 14184 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS) Main PID: 14185 (nginx) CGroup: /system.slice/nginx.service ├─14185 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf └─14186 nginx: worker process Oct 07 07:34:00 centos7 systemd[1]: Starting nginx - high performance web server... Oct 07 07:34:00 centos7 systemd[1]: Started nginx - high performance web server.
вот моя конфигурация nginx.service
cat /usr/lib/systemd/system/nginx.service [Unit] Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/ After=network-online.target remote-fs.target nss-lookup.target Wants=network-online.target [Service] Type=forking PIDFile=/var/run/nginx.pid ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf ExecReload=/bin/sh -c "/bin/kill -s HUP $(/bin/cat /var/run/nginx.pid)" ExecStop=/bin/sh -c "/bin/kill -s TERM $(/bin/cat /var/run/nginx.pid)" [Install] WantedBy=multi-user.target
Ответ №1:
Для тех, у кого есть SELinux == Принудительное исполнение, и Nginx возвращает 403 для статических файлов :
Включите функцию SELinux httpdcannetwork_connect
sudo setsebool -P httpd_can_network_connect on
проверьте соблюдение SELinux
getenforce
Если это принудительно —
chcon -Rt httpd_sys_content_t /home/static/