代码之家  ›  专栏  ›  技术社区  ›  nttaylor

nginx在supervisor下无法打开conf文件

  •  0
  • nttaylor  · 技术社区  · 7 年前

    我在RHEL7.5上,试图在Supervisor3.3.4下运行nginx1.14.0。最终目的是服务于Django网站。

    我的“/etc/init.d/supervisord”如下所示:

    #!/bin/sh
    ...
    # Source init functions
    . /etc/rc.d/init.d/functions
    
    prog="supervisord"
    prog_bin="/bin/supervisord -c /etc/supervisord.conf"
    PIDFILE="/var/run/$prog.pid"
    
    start()
    {
       echo -n $"Starting $prog: "
       daemon $prog_bin --pidfile $PIDFILE
       sleep 1
       [ -f $PIDFILE ] && success $"$prog startup" || failure $"$prog startup"
       echo
    }
    ... # "stop", "restart" functions, etc.
    

    [unix_http_server]
    file=/var/run//supervisor.sock 
    
    [supervisord]
    logfile=/var/log/supervisor/supervisord.log
    pidfile=/var/run/supervisord.pid
    childlogdir=/var/log/supervisor
    
    [rpcinterface:supervisor]
    supervisor.rpcinterface_factory = 
    supervisor.rpcinterface:make_main_rpcinterface
    
    [supervisorctl]
    serverurl=unix:///var/run//supervisor.sock
    
    [include]
    files = /etc/supervisor/conf.d/*.conf
    

    “/etc/supervisor/conf.d/”中只有一个文件:nginx.conf文件:

    [program:nginx]
    user=root
    command=/usr/sbin/nginx -c /path/to/site/etc/nginx.conf
    autostart=true
    autorestart=true
    startretries=3
    redirect_stderr=True
    

    使用直接调用上述命令 sudo /usr/sbin/nginx -c /path/to/site/etc/nginx.conf & ps -ef

    但如果我开始的话,我想这样:

    $ sudo /etc/init.d/supervisord restart
    

    $ sudo cat /var/log/supervisor/nginx-stdout---supervisor-tqI97D.log
    nginx: [emerg] open() "/path/to/site/etc/nginx.conf" failed (13: Permission denied)
    

    读取该文件的权限一直很好。当然,这条路不是 调用“/path/to/site/etc”/nginx.conf文件,但每个目录上的所有用户都有一个“x”,conf文件本身上的所有用户都有一个“r”:

    $ namei -om /path/to/site/etc/nginx.conf
    f: /path/to/site/etc/nginx.conf
     dr-xr-xr-x root    root   /
     drwxr-xr-x root    root   path
     drwxr-xr-x root    root   to
     drwxrwxr-x user1   group1 site
     drwxrwxr-x user1   group1 etc
     -rw-r--r-- root    group1 nginx.conf
    

    这是SELinux这一事实会有所不同吗?它现在被激活了。

    $ getenforce
    Enforcing
    

    如果有帮助的话nginx.conf文件无法打开的文件如下所示:

    user  nginx;
    daemon off;
    
    error_log  /path/to/site/var/log/nginx-error.log warn;
    pid        /path/to/site/var/run/nginx.pid;
    
    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"';
    
        access_log  /path/to/site/var/log/nginx-access.log  main;
    
        sendfile        on;
        #tcp_nopush     on;
    
        keepalive_timeout  65;
    
        #gzip  on;
    
        upstream app_server {
            server unix:/path/to/site/var/run/my-django.socket fail_timeout=0;
        }
    
        server {
            listen 8000;
            server_name xxx.xxx.xxx.xxx;
            charset utf-8;
    
            location /media  {
                alias /path/to/site/htdocs/media;
            }
    
            location /static {
                alias /path/to/site/htdocs/static;
            }
    
            location / {
                uwsgi_pass  app_server;
                include     /path/to/site/etc/uwsgi_params;
            }
        }
    }
    

    2 回复  |  直到 7 年前
        1
  •  0
  •   OldFart    7 年前

    我建议你去看看 SELinux 在对生产机器做任何事情之前,要真正掌握整个概念。

    httpd\u t上下文允许NGINX侦听公共web服务器端口、访问/etc/NGINX中的配置文件以及访问标准docroot位置(/usr/share/NGINX)中的内容。它不允许许多其他操作,例如代理到上游位置或通过套接字与其他进程通信。

    NGINX's - Modifying SELinux Settings

    让我们知道,祝你好运!

        2
  •  0
  •   sebasth    7 年前

    在启用SELinux的系统上,进程和文件具有安全标签。SELinux策略包含这些标签之间允许的访问模式。如果没有允许访问的规则,则拒绝访问。

    httpd_t 域尝试使用访问文件 default_t 标签。要允许访问,您需要为nginx文件分配适当的安全上下文。可能的上下文记录在 httpd_selinux man page . 对于配置文件,适当的上下文是 httpd_config_t httpd_user_content_t .

    可以使用手动将新的安全上下文应用于文件 chcon semanage . 否则,自动重新标记将错误地标记文件。

    我已经就有关Unix和Linux堆栈交换问题的主题写了一个更详细的答案 Configure SELinux to allow daemons to use files in non-default locations .