Nginx permission denied while loading virtual host file - Fedora 21

820 Views Asked by At

So I just installed nginx and everything works well for a start and I get the default nginx welcome message on my vps running fedora 21. Then when I try adding virtual hosts for my rails application, for some reason nginx is unable to load my virtual host file. It throws a permission denied error which I can't trace why its thrown. Tried everything possible but nothing seems to change.

nginx.conf

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log;
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;

pid        /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"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    index   index.html index.htm;

    # 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;

    # Load virtual host conf files. (line 44 below)
    include /etc/nginx/sites-enabled/*;

    server {
        listen       80 default_server;
        server_name  localhost;
        root         /usr/share/nginx/html;

        #charset koi8-r;

        #access_log  /var/log/nginx/host.access.log  main;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        }

        # redirect server error pages to the static page /40x.html
        #
        error_page  404              /404.html;
        location = /40x.html {
        }

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
        }
    }
}

myblog(/etc/nginx/sites-available/myblog)

upstream thin{
    server 127.0.0.1:3000;
    server 127.0.0.1:3001;
}

server {
    listen   80;
    # server_name  www.sitename.com;
    # rewrite ^/(.*) http://sitename.com/$1 permanent;
}


server {
    listen   80;
    # server_name sitename.com;

    access_log /home/deployer/nginx-access.log;
    error_log /home/deployer/nginx-error.log;

    root   /home/deployer/apps/myblog/current/public/;
    index  index.html;

    location ^~ /assets/ {
        gzip_static on;
        expires max;
        add_header Cache-Control public;
    }

    location / {
        proxy_set_header  X-Real-IP  $remote_addr;
        proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;

        if (-f $request_filename/index.html) {
            rewrite (.*) $1/index.html break;
        }

        if (-f $request_filename.html) {
            rewrite (.*) $1.html break;
        }

        if (!-f $request_filename) {
            proxy_pass http://thin;
            break;
        }
    }

}

The sites-enabled folder is symliked to the sites-available folder. On restarting nginx, I get this error

 nginx: [emerg] open() "/etc/nginx/sites-enabled/myblog" failed (13: Permission denied) in /etc/nginx/nginx.conf:44

Permissions of the myblog virtual host file

-rw-r--r--. 1 root root 1112 Jun  1 10:58 /etc/nginx/sites-available/myblog

Is there something i'm missing? I'm not sure why nginx cannot load my file. Thanks!

0

There are 0 best solutions below