Nginx error sudo nginx -t

I am getting below error

sudo nginx -t

Hi,

To resolve this issue, you can follow these steps:

  1. Edit the configuration file using a text editor. Assuming you have sudo access, you can use the following command:

    sudo nano /etc/nginx/conf.d/frappe-bench.conf
    
  2. Go to line 102 in the file and locate the log format configuration.The line might look something like this:

    log_format main ...
    

    Ensure that the log format is correctly defined. If the log format definition is missing or incorrect, you can modify it based on your requirements. Here’s an example of a basic log format:

      log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                        '"$http_user_agent" "$http_x_forwarded_for"';
    

    Modify the log format based on your specific needs or replace it with a valid log format configuration.

  3. Save the changes and exit the text editor.

  4. Validate the Nginx configuration to ensure it is error-free:

    sudo nginx -t
    

    If there are no syntax errors, the command will display a message indicating that the configuration file test passed.

  5. Restart Nginx for the changes to take effect:

    sudo systemctl restart nginx
    

Hope this will help you out.

Thank you.

1 Like

Thanks a lot for reply.

I didn’t find “log_format main” in a file “frappe-bench.conf”.

May I know if there is any correct place or heading where I should write this log format?

Thanks again.

Hi,

The log format “main” should be specified using the $log_format directive in the http block of the nginx configuration, but it is missing in this case.

To fix the issue, you can remove the word “main” from that line, so it becomes:

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

After making this change, you can save the file and try testing the Nginx configuration again using the following command:

sudo nginx -t

If there are no other syntax errors, the configuration test should be successful. Then, you can restart the Nginx service with the command:

sudo service nginx restart

Hope this will help you out.

Thank you.