Jump to content

Adding servers to nginx? (SOLVED)


Scott B

Recommended Posts

I have a docker image running on my unraid server. I would like to reverse proxy it through the existing nginx instance that is serving up the unraid website. Although I have managed the changes required to the nginx config file, obviously it is overwritten every time the unraid server reboots. Is there any supported way I can persist this so that it survives reboots?

Edited by Scott B
marking as solved
Link to comment

Thanks for the reply. I see that the link you provided will create a new docker network and another separate nginx instance. This is definitely an option - just curious if it is the only option? The only reason we can't use the existing nginx installation is due to the configuration file being erased at reboot. I have tested creating an nginx configuration and it does work if you restart nginx.

Link to comment

I solved the problem, and once I found the right plugin it was pretty easy! The docker image I am working with is Technitium DNS

  1.  I set the docker container network to "host"

  2. I installed CA User Scripts and created a new user script called enable-nginx-extensions with the following:

    #!/bin/bash
    # remove the config file if it already exists
    rm /etc/nginx/conf.d/nginx_extend.conf
    # symlink to the config file stored on the boot volume with the user script
    ln -s /boot/config/plugins/user.scripts/scripts/enable-nginx-extensions/nginx_extend.conf /etc/nginx/conf.d/
    # restart nginx so that the new configuration file is picked up
    /etc/rc.d/rc.nginx restart

     

  3.  I created a configuration file and stored it at /boot/config/plugins/user.scripts/scripts/enable-nginx-extensions/nginx_extend.conf

    server {
            listen 80;
            server_name new_server_name.local;
            location / {
                    proxy_pass http://localhost:5380/;
                    allow all;
            }
    }

    A couple of things to take note of:

    1. You must specify a server name - unraid is the default server and you can't change that. it has to be that way. Don't fight it :)

    2. Set the proxy_pass line to the ip/port where the upstream server is serving your application

    3. The allow all line is very important - without it, the application will try to authenticate the user against the unraid auth. This is almost certainly not what you want.

  4. I set the script to run at array start.

  5. I verified that my new site was available and restarted things a couple of times to make sure it persisted.

I hope these steps help someone else out in the future!

Edited by Scott B
Fixed comment in the script and updated steps in comment to be more accurate
  • Thanks 1
Link to comment
  • Scott B changed the title to Adding servers to nginx? (SOLVED)
  • 3 years later...
On 1/25/2021 at 12:02 PM, Scott B said:

I solved the problem, and once I found the right plugin it was pretty easy! The docker image I am working with is Technitium DNS

  1.  I set the docker container network to "host"

  2. I installed CA User Scripts and created a new user script called enable-nginx-extensions with the following:

    #!/bin/bash
    # remove the config file if it already exists
    rm /etc/nginx/conf.d/nginx_extend.conf
    # symlink to the config file stored on the boot volume with the user script
    ln -s /boot/config/plugins/user.scripts/scripts/enable-nginx-extensions/nginx_extend.conf /etc/nginx/conf.d/
    # restart nginx so that the new configuration file is picked up
    /etc/rc.d/rc.nginx restart

     

  3.  I created a configuration file and stored it at /boot/config/plugins/user.scripts/scripts/enable-nginx-extensions/nginx_extend.conf

    server {
            listen 80;
            server_name new_server_name.local;
            location / {
                    proxy_pass http://localhost:5380/;
                    allow all;
            }
    }

    A couple of things to take note of:

    1. You must specify a server name - unraid is the default server and you can't change that. it has to be that way. Don't fight it :)

    2. Set the proxy_pass line to the ip/port where the upstream server is serving your application

    3. The allow all line is very important - without it, the application will try to authenticate the user against the unraid auth. This is almost certainly not what you want.

  4. I set the script to run at array start.

  5. I verified that my new site was available and restarted things a couple of times to make sure it persisted.

I hope these steps help someone else out in the future!

 

This doesn't work for me. I don't think that the files in `/etc/nginx/conf.d/` are automatically being picked up. Am I missing something? 

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...