Skip to content

Conversation

@enwikuna
Copy link

Updated regex patterns for extracting nginx configuration paths and added fallback mechanisms for determining paths on different operating systems. Improved error handling and logging for better debugging.

If we have helped you, please leave our company a nice review: https://g.page/r/CaNMAPSpl68TEBM/review

Updated regex patterns for extracting nginx configuration paths and added fallback mechanisms for determining paths on different operating systems. Improved error handling and logging for better debugging.
@0xJacky
Copy link
Owner

0xJacky commented Oct 29, 2025

Thank you for your contribution.

@0xJacky 0xJacky requested a review from Copilot October 29, 2025 16:34
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors nginx path resolution functions to improve robustness and provide better fallback behavior. Instead of returning empty strings when parsing fails, the code now falls back to reasonable defaults.

Key changes include:

  • Improved regex patterns for parsing nginx configuration paths from nginx -V output
  • Added fallback mechanisms for GetConfPath, GetConfEntryPath, and GetPIDPath when parsing fails
  • Enhanced error handling with debug logging for fallback scenarios
  • For PID path, added probing of common locations (/var/run/nginx.pid, /run/nginx.pid) when the configured path isn't found

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

out := getNginxV()
r, _ := regexp.Compile(`--conf-path=([^\s]+)`)
match := r.FindStringSubmatch(out)

Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixed indentation detected: tabs and spaces are inconsistent. Line 69 uses tabs while the surrounding lines (65-68, 70-81) use spaces for indentation. This should be standardized to match the project's indentation style (appears to be tabs based on other parts of the file).

Suggested change

Copilot uses AI. Check for mistakes.
} else {
confPath = "/etc/nginx"
}

Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixed indentation detected: line 79 uses tabs while the surrounding lines use spaces. This should be standardized to match the project's indentation style.

Suggested change

Copilot uses AI. Check for mistakes.
path = match[1]
} else {
baseDir := GetConfPath()

Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixed indentation detected: line 108 uses tabs while the surrounding lines use spaces. This should be standardized to match the project's indentation style.

Suggested change

Copilot uses AI. Check for mistakes.
Comment on lines +107 to +109
baseDir := GetConfPath()

if baseDir != "" {
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential infinite recursion: GetConfEntryPath calls GetConfPath() as a fallback (line 107), which could lead to circular dependency issues if GetConfPath ever needs to call GetConfEntryPath. While this may not happen in the current code, consider passing a flag or using a different approach to avoid this pattern.

Copilot uses AI. Check for mistakes.
Comment on lines +136 to +138
candidates := []string{
"/var/run/nginx.pid",
"/run/nginx.pid",
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hardcoded candidate paths for PID files don't include Windows-specific locations. Consider adding Windows-specific candidates (e.g., relative to GetPrefix() or GetNginxExeDir()) or conditionally defining candidates based on runtime.GOOS to ensure cross-platform compatibility.

Suggested change
candidates := []string{
"/var/run/nginx.pid",
"/run/nginx.pid",
var candidates []string
if runtime.GOOS == "windows" {
exeDir := GetNginxExeDir()
prefix := GetPrefix()
candidates = []string{
filepath.Join(exeDir, "nginx.pid"),
filepath.Join(exeDir, "logs", "nginx.pid"),
filepath.Join(prefix, "nginx.pid"),
filepath.Join(prefix, "logs", "nginx.pid"),
}
} else {
candidates = []string{
"/var/run/nginx.pid",
"/run/nginx.pid",
}

Copilot uses AI. Check for mistakes.
@enwikuna
Copy link
Author

Thank you for your contribution.

You should create a hotfix out of it. Did some additional tests today and its unable with the current version to setup a running NGINX UI inside Docker...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants