pelican
pelican

Reputation: 6234

Nginx service not starting on Windows 10 - nginx: [alert] could not open error log file: CreateFile()

I have an Nginx service that's configured to start automatically on my Windows 10; however, this morning, the service wouldn't start. The error log says: nginx: [alert] could not open error log file: CreateFile() "C:\someForlderName\build\distribution\.\nginx/logs/error.log" failed (3: The system cannot find the path specified)

Looking at the path in the error log above, I do NOT have the /logs/ folder on my local system so it looks like Nginx doesn't have the proper permissions to create that folder?

I'm setup as an admin user and my service is set to Log On As - Local System Account

This only happens on Windows 10; but the service starts and works on older Windows i.e 8.1

So does anyone know how to grant administrator's permissions to Nginx so that Nginx can create folders and files on Windows 10 ?

Upvotes: 11

Views: 40141

Answers (6)

hiroaki415
hiroaki415

Reputation: 1

I found a solution for people who have to execute from the directory containing nginx.exe even if you configured $ENV:Path for it. So, I leave it here as my reminder.

I don't know why, but it seems that a shortcut (.lnk) linked to nginx.exe can be executed from any directory without path finding error like above.

Here is my suggestion:

  1. Create shortcut (.lnk) linked to nginx.exe, then place it in a directory as you wish.

  2. Set alias {shortcut}.lnk as nginx in your PowerShell's profile (i.e inside $HOME\Documents\PowerShell\Profile.ps1)

    like this:

    Set-Alias -Name nginx -Value C:\directory\to\{shortcut}.lnk

  3. Reload PowerShell

Then, now you can execute nginx command from any directory like Unix/Linux system with the path properly configured.

Upvotes: 0

Eric McWinNEr
Eric McWinNEr

Reputation: 533

I had a similar issue with starting the nginx server, but after looking at it closely and trying to run the command in different consoles, I realized it just a simple issue of a missing path.

How I solved it was to cd into the containing folder for the nginx.exe file (which actually contains error logs and all the necessary files) and then run the nginx command which started the server and fixed it for me.

Upvotes: 2

David Wahid
David Wahid

Reputation: 11

  1. After downloading zip file, you have unzip.
  2. Make sure that you dont have nested folder names. You have to copy your folder which has nginx.exe file in it, and paste it into C:/ folder.
  3. While running commands, like nginx -s stop, make sure that current your working directory is same as the nginx.exe file. enter image description here

Upvotes: 1

harun ugur
harun ugur

Reputation: 1852

Nginx start on default port 80, not 8080. Try localhost:80 on browser.

If you want to change port, open C:\nginx-1.16.1\conf\nginx.conf with text editor. change port number what you want use default port.

server {
    listen       80;
    server_name  localhost;
to:

server {
    listen       8080;
    server_name  localhost;

Upvotes: 0

Diep Gepa
Diep Gepa

Reputation: 515

You need:

To install nginx/Windows, download the latest mainline version distribution (1.13.8), since the mainline branch of nginx contains all known fixes. Then unpack the distribution, go to the nginx-1.13.8 directory, and run nginx. Here is an example for the drive C: root directory: (Run cmd as administrator)

cd c:\
unzip nginx-1.13.8.zip
cd nginx-1.13.8
start nginx

Go to: http://localhost:80 -> test install

Goback to console cmd: "nginx -s stop"

Run for next time:

  1. Config with file: "C:\nginx-1.13.8\conf\nginx.conf"
  2. Open cmd as administrator
  3. Run bash: "cd C:\nginx-1.13.8"
  4. Run nginx with bash: "start nginx" . If you run with bash: "nginx", will get trouble for exit nginx.
  5. And

    nginx -s stop #fast shutdown

    nginx -s quit #graceful shutdown

    nginx -s reload #changing configuration, starting new worker processes with a new configuration, graceful shutdown of old worker processes

    nginx -s reopen #re-opening log files

Upvotes: 10

Richard Li
Richard Li

Reputation: 416

Under the directory that you run nginx.exe, try to create a directory named logs, and a file named error.log under log. It should pass this error.

Upvotes: 4

Related Questions