You are not logged in.

#1 2017-01-03 20:10:12

green_heron
Member
Registered: 2015-08-16
Posts: 16

Problem with nginx server block

Hello guys,

I'm trying to set up few server blocks on nginx. I want have a web development environment on my laptop (without docker, vagrant etc). I installed:
- nginx
- php-fpm
- mariadb

I created sites-enabled directory in /etc/nginx and include this path in nginx.conf. Inside sites-enabled I have file example with this:

server {
  listen 80;
  listen [::]:80;
  server_name app.dev www.app.dev;
  root /home/matt/dev/app;
  index index.php index.html index.htm index.nginx-debian.html;

  location / {
    try_files $uri $uri/ =404;
  }

  error_page 404 /404.html;
  error_page 500 502 503 504 /50x.html;

  location = /50x.html {
    root /home/matt/dev/app;
  }

	location ~ \.php$ {
	  fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
	  fastcgi_index index.php;
	  include fastcgi.conf;
	}

  location ~ /\.ht {
    deny all;
  }
}

After restart php, nginx and go to app.dev I see 404 Not Found. This error is in default nginx root directory too (/usr/share/nginx/html)

Any ideas how can I fix this

Thanks in advance for all help

smile

Offline

#2 2017-01-03 20:24:13

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: Problem with nginx server block

Can you post your /etc/nginx/nginx.conf as well please.

Does the nginx user (usually http) have read access to the appropriate directories?


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#3 2017-01-03 20:34:39

green_heron
Member
Registered: 2015-08-16
Posts: 16

Re: Problem with nginx server block

Here is my nginx.conf

#user html;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    include /etc/nginx/sites-enabled/*;
    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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

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

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

Now I changed this "example" file to this:

server {
    listen 80;
    server_name app.dev www.app.dev;
    root /home/matt/dev/app;
    location / {
        index index.html index.htm index.php;
    }

    location ~ \.php$ {
        #fastcgi_pass 127.0.0.1:9000; (depending on your php-fpm socket configuration)
        fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        include fastcgi.conf;
    }
}

and I see 403 error insted of 404

Edit.
After I changed this server block I can access default nginx block (127.0.0.1) without any errors

Last edited by green_heron (2017-01-03 20:37:04)

Offline

#4 2017-01-04 02:58:39

skarphace
Member
Registered: 2009-01-07
Posts: 22

Re: Problem with nginx server block

Most likely problem is your permissions.  Unless you're running nginx as user 'matt', nginx can not view files in his home directory.  Try moving them to something like /var/www and making sure wherever it is, nginx has read access to the files.

Offline

#5 2017-01-04 11:29:37

green_heron
Member
Registered: 2015-08-16
Posts: 16

Re: Problem with nginx server block

Root directory of this server block has:
Chmod 777 and I was trying chown http:http and chown matt:matt
Both variants failed.

Last edited by green_heron (2017-01-04 11:30:05)

Offline

#6 2017-01-04 12:01:16

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: Problem with nginx server block

The http user needs read access to the parent directories as well, if you look at the output of ls -lh /home you'll see that the http user doesn't have the permissions to view anything in your home directory.

This is why it's recommended to keep all of your root directories in a location such as /var/www with the correct permissions.


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#7 2017-01-04 19:07:22

green_heron
Member
Registered: 2015-08-16
Posts: 16

Re: Problem with nginx server block

Thanks guys for help. I moved my project to /usr/share/nginx/projectname and everything works fine.

Offline

Board footer

Powered by FluxBB