0

Fresh install of nginx on FreeBSD 11.0_RELEASE. Default nginx.conf with one mod to comment out the pid. See the conf below. The error:

nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: [emerg] open() "/var/run/nginx.pid" failed (13: Permission denied)
nginx: configuration file /usr/local/etc/nginx/nginx.conf test failed

Default nginx.conf:

# user  nobody;
worker_processes  1;

# This default error log path is compiled-in to make sure configuration parsing
# errors are logged somewhere, especially during unattended boot when stderr
# isn't normally logged anywhere. This path will be touched on every nginx
# start regardless of error log location configured here. See
# https://trac.nginx.org/nginx/ticket/147 for more info.
#
#error_log  /var/log/nginx/error.log;
#

#pid        logs/nginx.pid;


events {
        worker_connections  1024;
}


http {
        include       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  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/local/www/nginx;
                        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/local/www/nginx-dist;
                }

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

}

I'm trying to get a basic setup to work, but nginx won't pass tests and won't start. I am expecting it to start, naturally. My question is "how do I fix this?" I've never run into this before on FreeBSD, or any other OS for that matter.

The pid is commented out because rc.d already points to the pid, as the error shows. There is no permanent nginx.pid file in that location.

nbari
  • 25,603
  • 10
  • 76
  • 131
Rich_F
  • 1,830
  • 3
  • 24
  • 45
  • Also tried with user as `root`, group `admin`. – Rich_F Jul 05 '17 at 16:30
  • In FreeBSD there is no group admin by default, did you change something? – nbari Jul 06 '17 at 07:43
  • No, I said I tried it. It is now serving http for some reason, but giving me the same errors. I tried changing to root::admin to get around the permissions issue. – Rich_F Jul 06 '17 at 11:17

1 Answers1

1

After installing Nginx do:

sysrc nginx_enable="YES"

Then to start the service

service nginx start

or

/usr/local/etc/rc.d/nginx start

Probably this may also work:

service nginx configtest

By default, the pid is in /var/run/nginx.pid

Later you can just do:

nginx -t

or

nginx -T

And should work with out printing any errors.

nbari
  • 25,603
  • 10
  • 76
  • 131
  • Turns out it started it self somehow this afternoon. Even after a couple reboots, I couldn't see it working. Had the `nginx_enable=YES` already in there, and the `service nginx start` wasn't working. So it has progressed. Thank you. – Rich_F Jul 05 '17 at 22:23
  • Try removing it, and later install `pkg install nginx-lite` should work out of the box. – nbari Jul 05 '17 at 22:26
  • Did that. Even tried installing nginx-full, then back to nginx. Using ports. I've never seen a service, nor a pid file, and these errors. I'll push through it some more. – Rich_F Jul 05 '17 at 22:31
  • Reinstalled the complete OS, 11.1-RC1, and got the default `nginx.conf`working. Then replaced the server pointers, got the `nginx.pid` permissions errors. Reinstalled the default `nginx.conf` and the permissions issues are remaining. – Rich_F Jul 10 '17 at 21:27
  • What do you mean with server pointers, check also output of `nginx -V` to se full paths – nbari Jul 11 '17 at 00:02
  • I was going to use `vhosts` or `virtual hosts` but those are Apache terms from what I remember. It's serving a handful of domains. Why do I need to see the paths? Everything is in order. Permissions are the issue. – Rich_F Jul 11 '17 at 00:35
  • is `nginx -V` printing something like `--pid-path=/var/run/nginx.pid` ? in any case try to use `ktrace` maybe that can give you a clue about what may be wrong, try to reproduce this pattern if possible and if necessary file a bug report https://www.freebsd.org/support/bugreports.html – nbari Jul 11 '17 at 08:15
  • yes, --pid-path=/var/run/nginx.pid. It just makes no sense that it needs permissions changed after I changed nginx.conf. Anyway, fixed because I changed the nginx.conf. Very strange. – Rich_F Jul 11 '17 at 15:31