Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am on a shared host with rights to inherit the nginx root installation and overriding it's config file (note: I do NOT want to compile my own nginx in my home directory).

I wrote a start/reload/stop script which works perfectly however I keep getting the error below

the startup script

#!/bin/bash

# Set this to your nginx configuration file and PID

CONFIG=~/nginx/nginx.conf
PIDFILE=~/nginx/nginx.pid


# Do not change anything below unless you know what you do

DAEMON=/usr/local/nginx/sbin/nginx
NAME="nginx"
PATH=/sbin:/bin:/usr/sbin:/usr/bin
OPTS="-c $CONFIG"

...

My config:

worker_processes  4;

error_log  /home/myusername/nginx/error.log;
pid        /home/myusername/nginx/nginx.pid;

events {
    worker_connections  8192;
    multi_accept on;
    use epoll;
}

http {
    error_log /home/myusername/nginx/error.log;
    access_log /home/myusername/nginx/access.log;
    server_names_hash_max_size 8192;
    server_names_hash_bucket_size 128;
    include       /etc/nginx/mime.types;
    underscores_in_headers on;
...

The error:

Reloading nginx configuration: [alert]: could not open error log file: open() "/usr/local/nginx/logs/error.log" failed (13: Permission denied)
nginx.

So it seems it's not reading my error and acces log locations correctly, how do I solve this, thanks!

share|improve this question
    
Perhaps you could snip less of your startup script? It looks like it's testing the wrong config file. –  Martin Fjordvald Sep 7 '11 at 12:59

2 Answers 2

NGINX searches for the built-in error log location, before it reads your config file.

You can find this in here: http://wiki.nginx.org/CoreModule under the error_log section.

"Also note that as of version 0.7.53, nginx will use a compiled-in default error log location until it has read the config file. If the user running nginx doesn't have write permission to this log location, nginx will raise an alert like this:

[alert]: could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied) "

share|improve this answer
    
This is true, but how can this be solved? (How to run nginx as non-root?) –  Etienne Perot Mar 14 '12 at 15:01

I've been able to get this to work using the -p option, setting the prefix to a path I can write to.

$ nginx -p . -c my-nginx.conf
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.