NGINX Configuration for RHEL #7560

Closed
opened 2025-12-29 20:25:25 +01:00 by adam · 8 comments
Owner

Originally created by @Nealtron on GitHub (Jan 25, 2023).

Change Type

Addition

Area

Installation/upgrade

Proposed Changes

Just finished deploying NetBox on Redhat Enterprise 9 with NGINX 1.20.1 from the Redhat official repo, and most of the documentation regarding NGINX configuration wasn't valid.

# uname -a
Linux netbox.<REDACTED> 5.14.0-162.6.1.el9_1.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Sep 30 07:36:03 EDT 2022 x86_64 x86_64 x86_64 GNU/Linux
# nginx -v
nginx version: nginx/1.20.1

Basically, you can boil down the configuration from the current documentation to:

# Install NGINX
sudo yum install -y nginx

# Create NGINX Config
sudo mkdir /etc/nginx/sites-available
sudo mkdir /etc/nginx/sites-available/netbox
sudo cp /opt/netbox/contrib/nginx.conf /etc/nginx/sites-available/netbox

# Replace NGINX Default site with NetBox
sudo rm /etc/nginx/sites-enabled/default
sudo ln -s /etc/nginx/sites-available/netbox /etc/nginx/sites-enabled/netbox

# Start NGINX
sudo systemctl restart nginx

But both the "sites-available" and "sites-enabled" directories don't exist. Creating the missing directories and re-running the previously failing steps didn't work.

Now for the fix. I don't know if this is the correct way of handling this, but I replaced the server stanzas of the /etc/nginx/nginx.conf file with the contents of /opt/netbox/contrib/nginx.conf and the site loads fine now.

more nginx.conf

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#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 [::]:443 ssl ipv6only=off;

    # CHANGE THIS TO YOUR SERVER'S NAME
    server_name netbox.<REDACTED>;

    ssl_certificate /etc/ssl/certs/netbox.crt;
    ssl_certificate_key /etc/ssl/private/netbox.key;

    client_max_body_size 25m;

    location /static/ {
        alias /opt/netbox/netbox/static/;
    }

    location / {
        proxy_pass http://127.0.0.1:8001;
        proxy_set_header X-Forwarded-Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

server {
    # Redirect HTTP traffic to HTTPS
    listen [::]:80 ipv6only=off;
    server_name _;
    return 301 https://$host$request_uri;
}
}
Originally created by @Nealtron on GitHub (Jan 25, 2023). ### Change Type Addition ### Area Installation/upgrade ### Proposed Changes Just finished deploying NetBox on Redhat Enterprise 9 with NGINX 1.20.1 from the Redhat official repo, and most of the documentation regarding NGINX configuration wasn't valid. ``` # uname -a Linux netbox.<REDACTED> 5.14.0-162.6.1.el9_1.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Sep 30 07:36:03 EDT 2022 x86_64 x86_64 x86_64 GNU/Linux # nginx -v nginx version: nginx/1.20.1 ``` Basically, you can boil down the configuration from the [current documentation](https://docs.netbox.dev/en/stable/installation/5-http-server/) to: ``` # Install NGINX sudo yum install -y nginx # Create NGINX Config sudo mkdir /etc/nginx/sites-available sudo mkdir /etc/nginx/sites-available/netbox sudo cp /opt/netbox/contrib/nginx.conf /etc/nginx/sites-available/netbox # Replace NGINX Default site with NetBox sudo rm /etc/nginx/sites-enabled/default sudo ln -s /etc/nginx/sites-available/netbox /etc/nginx/sites-enabled/netbox # Start NGINX sudo systemctl restart nginx ``` But both the "sites-available" and "sites-enabled" directories don't exist. Creating the missing directories and re-running the previously failing steps didn't work. Now for the fix. I don't know if this is the correct way of handling this, but I replaced the server stanzas of the /etc/nginx/nginx.conf file with the contents of /opt/netbox/contrib/nginx.conf and the site loads fine now. ``` more nginx.conf #user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #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 [::]:443 ssl ipv6only=off; # CHANGE THIS TO YOUR SERVER'S NAME server_name netbox.<REDACTED>; ssl_certificate /etc/ssl/certs/netbox.crt; ssl_certificate_key /etc/ssl/private/netbox.key; client_max_body_size 25m; location /static/ { alias /opt/netbox/netbox/static/; } location / { proxy_pass http://127.0.0.1:8001; proxy_set_header X-Forwarded-Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; } } server { # Redirect HTTP traffic to HTTPS listen [::]:80 ipv6only=off; server_name _; return 301 https://$host$request_uri; } } ```
adam added the type: documentationpending closure labels 2025-12-29 20:25:25 +01:00
adam closed this issue 2025-12-29 20:25:25 +01:00
Author
Owner

@jeremystretch commented on GitHub (Jan 25, 2023):

Just finished deploying NetBox on Redhat Enterprise 9 with NGINX 1.20.1 from the Redhat official repo, and most of the documentation regarding NGINX configuration wasn't valid.

We don't provide documentation for RHEL. The installation docs cover only Ubuntu and CentOS. It is normal and expected to encounter differences on other distributions.

@jeremystretch commented on GitHub (Jan 25, 2023): > Just finished deploying NetBox on Redhat Enterprise 9 with NGINX 1.20.1 from the Redhat official repo, and most of the documentation regarding NGINX configuration wasn't valid. We don't provide documentation for RHEL. The [installation docs](https://docs.netbox.dev/en/stable/installation/) cover only Ubuntu and CentOS. It is normal and expected to encounter differences on other distributions.
Author
Owner

@Nealtron commented on GitHub (Jan 25, 2023):

That's reasonable, but I don't suspect this is a REHL specific issue. Based on my research, none of the CentOS family of linux Distros (CentOS, RHEL, Fedora, etc.) utilize a single NGINX.conf file, whereas the Debian family of distros are configured to include any config file located within sites-enabled.

https://stackoverflow.com/questions/17413526/nginx-missing-sites-available-directory

It's worth noting that the directions worked perfectly for the first 4 phases of the install (Postgres through Gunicorn) in the event you wanted to officially document RHEL.

@Nealtron commented on GitHub (Jan 25, 2023): > That's reasonable, but I don't suspect this is a REHL specific issue. Based on my research, none of the CentOS family of linux Distros (CentOS, RHEL, Fedora, etc.) utilize a single NGINX.conf file, whereas the Debian family of distros are configured to include any config file located within sites-enabled. https://stackoverflow.com/questions/17413526/nginx-missing-sites-available-directory It's worth noting that the directions worked perfectly for the first 4 phases of the install (Postgres through Gunicorn) in the event you wanted to officially document RHEL.
Author
Owner

@jeremystretch commented on GitHub (Jan 25, 2023):

For the HTTP server configuration specifically, we only provide instructions for Ubuntu as noted here (unlike the first few steps):

For the sake of brevity, only Ubuntu 20.04 instructions are provided here. These tasks are not unique to NetBox and should carry over to other distributions with minimal changes. Please consult your distribution's documentation for assistance if needed.

I'm not necessarily opposed to continuing CentOS instructions here, but some thought would need to be given to organization.

@jeremystretch commented on GitHub (Jan 25, 2023): For the HTTP server configuration specifically, we only provide instructions for Ubuntu as noted [here](https://docs.netbox.dev/en/stable/installation/5-http-server/) (unlike the first few steps): > For the sake of brevity, only Ubuntu 20.04 instructions are provided here. These tasks are not unique to NetBox and should carry over to other distributions with minimal changes. Please consult your distribution's documentation for assistance if needed. I'm not necessarily opposed to continuing CentOS instructions here, but some thought would need to be given to organization.
Author
Owner

@BTGUK commented on GitHub (Jan 30, 2023):

I just came across the same issue (Oracle Linux in my case, but it's essentially the same on all RHEL derivates like CentOS). All steps worked fine right to the end when it came to configuring the HTTP server, which obviously failed due to the config differences between Ubuntu and CentOS.

From a user perspective, this is really a very poor experience. It makes no sense to provide step-by-step guides for CentOS just to leave the user hanging at the last step without instructions. A statement saying that the tasks "should carry over to other distributions with minimal changes" isn't helpful and hardly better than a "RTFM". It also raises the question why, instead of the non-helpful statement, the actual changes needed for CentOS weren't just listed.

When searching for a fix I came across forum postings regarding the lack of instructions for CentOS users from as far back as 2018.

@BTGUK commented on GitHub (Jan 30, 2023): I just came across the same issue (Oracle Linux in my case, but it's essentially the same on all RHEL derivates like CentOS). All steps worked fine right to the end when it came to configuring the HTTP server, which obviously failed due to the config differences between Ubuntu and CentOS. From a user perspective, this is really a very poor experience. It makes no sense to provide step-by-step guides for CentOS just to leave the user hanging at the last step without instructions. A statement saying that the tasks "should carry over to other distributions with minimal changes" isn't helpful and hardly better than a "RTFM". It also raises the question why, instead of the non-helpful statement, the actual changes needed for CentOS weren't just listed. When searching for a fix I came across forum postings regarding the lack of instructions for CentOS users from as far back as 2018.
Author
Owner

@jsenecal commented on GitHub (Jan 31, 2023):

Hi @BTGUK , would you be open to contribute to the project and submit a proposal for the NGINX related documentation ?

@jsenecal commented on GitHub (Jan 31, 2023): Hi @BTGUK , would you be open to contribute to the project and submit a proposal for the NGINX related documentation ?
Author
Owner

@BTGUK commented on GitHub (Feb 1, 2023):

Hi @jsenecal, if there's something I can contribute then of course I'd be glad to help, but pretty much all I did was following alternative guides I found on the web, such as this one:

https://www.centlinux.com/2021/11/install-netbox-on-centos-red-hat.html#point8

I believe, in general, any guide for CentOS should avoid trying to re-create Ubuntu's folder structure as this may well lead to other issues down the line (the guide in the link doesn't appear to do this).

My suggestion would be to simply add the nginx setup instructions from that website to the Netbox documentation so CentOS users have at least the steps for their platform for one webserver (the statement on the docu website saying that the instructions only show Ubuntu could be changed so it applies to the apache steps only).

@BTGUK commented on GitHub (Feb 1, 2023): Hi @jsenecal, if there's something I can contribute then of course I'd be glad to help, but pretty much all I did was following alternative guides I found on the web, such as this one: [https://www.centlinux.com/2021/11/install-netbox-on-centos-red-hat.html#point8](url) I believe, in general, any guide for CentOS should avoid trying to re-create Ubuntu's folder structure as this may well lead to other issues down the line (the guide in the link doesn't appear to do this). My suggestion would be to simply add the nginx setup instructions from that website to the Netbox documentation so CentOS users have at least the steps for their platform for one webserver (the statement on the docu website saying that the instructions only show Ubuntu could be changed so it applies to the apache steps only).
Author
Owner

@github-actions[bot] commented on GitHub (May 3, 2023):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide.

@github-actions[bot] commented on GitHub (May 3, 2023): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. **Do not** attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Author
Owner

@github-actions[bot] commented on GitHub (Jun 2, 2023):

This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.

@github-actions[bot] commented on GitHub (Jun 2, 2023): This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7560