我有以下设置来为实例nginx
提供uwsgi
服务cgit
。
# cat /etc/uwsgi.d/cgit.ini
[uwsgi]
plugins = cgi
uid = nginx
gid = nginx
socket = /srv/http/cgit/cgit.sock
procname-master = uwsgi cgit
processes = 1
threads = 2
cgi = /srv/http/cgit/htdocs/cgit.cgi
logto = /srv/http/cgit/logs/uwsgi.log
uwsgi 实例运行正常(配置文件中没有任何异常),套接字权限似乎正确,即nginx
所有者。我仔细检查了一下,用户nginx
是否可以访问目录并查看套接字。
# ls -la /srv/http/cgit
total 20
drwxr-xr-x. 5 nginx nginx 4096 Oct 29 14:09 .
drwxr-xr-x. 3 nginx nginx 4096 Oct 29 12:59 ..
drwxrwxr-x. 6 nginx nginx 4096 Oct 29 14:06 build
srwxr-xr-x. 1 nginx nginx 0 Oct 29 14:28 cgit.sock
drwxr-xr-x. 2 nginx nginx 4096 Oct 29 14:06 htdocs
drwxr-xr-x. 2 nginx nginx 4096 Oct 29 13:54 logs
我的 nginx 配置如下:
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
location /cgit-web {
rewrite ^/cgit-web(/.*)$ $1 break;
root /srv/http/cgit/build;
}
location /cgit {
try_files $uri @cgit;
}
location @cgit {
gzip off;
include uwsgi_params;
uwsgi_modifier1 9;
uwsgi_pass unix:/srv/http/cgit/cgit.sock;
}
}
}
用户是nginx
,并且套接字文件的路径也正确。现在,尝试访问时/cgit
,我在 nginx 的错误日志中发现以下消息:
*6 connect() to unix:/srv/http/cgit/cgit.sock failed (13: Permission denied) while connecting to upstream, client: x.x.x.x, server: _, request: "GET /cgit HTTP/1.1", upstream: "uwsgi://unix:/srv/http/cgit/cgit.sock:", host: "xxx"
我哪些权限弄错了?为什么无法nginx
访问套接字?
问题出在 SELinux 上。谢谢!