Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Location prefix behind reverse proxy + Button For Reload Configuration #53

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,60 @@ server {
2. Run `nginx -t` to make sure, that your config is valid
3. Run `systemctl restart nginx` (or equivalent) to restart your nginx and apply the new settings
4. Your nginx ui is now accessible at nginx.mydomain.com and will correctly prompt for basic auth

### Example NginX-UI + NginX (run in container) behind path '/some-location'

docker-compose.yml
```yaml
version: '3'
services:
nginx-ui:
container_name: nginx-ui
build: .
image: schenkd/nginx-ui:latest
# ports:
# - 8080:8080
volumes:
- D:/_data/_docker/nginx:/etc/nginx
Copy link
Owner

Choose a reason for hiding this comment

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

Could you adjust the volume mounts to a unix path? I don't want to get requests related to windows support since I don't have a windows machine where I could test it. Thanks mate!

networks:
- my-custom-network
nginx:
container_name: nginx
image: nginx:latest
ports:
- 80:80
volumes:
- D:/_data/_docker/nginx:/etc/nginx
networks:
- my-custom-network
networks:
my-custom-network:
name: my-custom-network
external: true
```

default.conf
```none
server {

listen 80;
listen [::]:80;
server_name localhost;

# ...

location /nginx-ui/ {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

# Need to pass this header for backend procesing route '/nginx-ui' + '/api'
proxy_set_header X-Forwarded-Prefix /nginx-ui;

# With docker custom network, we can use container name with port
# We cannot access port 8080 directly from outside host server
proxy_pass http://nginx-ui:8080/;
}

}
```
6 changes: 6 additions & 0 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@
from config import config
from flask_moment import Moment

from werkzeug.middleware.proxy_fix import ProxyFix

moment = Moment()


def create_app(config_name):
app = Flask(__name__)

app.wsgi_app = ProxyFix(
app.wsgi_app, x_for=1, x_proto=1, x_host=1, x_prefix=1
)

app.config.from_object(config[config_name])

config[config_name].init_app(app)
Expand Down
10 changes: 5 additions & 5 deletions app/static/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function add_domain() {

$.ajax({
type: 'POST',
url: '/api/domain/' + name,
url: 'api/domain/' + name,
statusCode: {
201: function() { fetch_domain(name) }
}
Expand All @@ -37,7 +37,7 @@ function enable_domain(name, enable) {

$.ajax({
type: 'POST',
url: '/api/domain/' + name + '/enable',
url: 'api/domain/' + name + '/enable',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
data: JSON.stringify({
Expand All @@ -56,7 +56,7 @@ function update_domain(name) {

$.ajax({
type: 'PUT',
url: '/api/domain/' + name,
url: 'api/domain/' + name,
contentType: 'application/json; charset=utf-8',
dataType: 'json',
data: JSON.stringify({
Expand Down Expand Up @@ -88,7 +88,7 @@ function remove_domain(name) {

$.ajax({
type: 'DELETE',
url: '/api/domain/' + name,
url: 'api/domain/' + name,
statusCode: {
200: function() {
load_domains();
Expand Down Expand Up @@ -121,7 +121,7 @@ function update_config(name) {

$.ajax({
type: 'POST',
url: '/api/config/' + name,
url: 'api/config/' + name,
contentType: 'application/json; charset=utf-8',
dataType: 'json',
data: JSON.stringify({
Expand Down
2 changes: 1 addition & 1 deletion app/static/custom.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions docker-compose.windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: '3'

services:

nginx-ui:
container_name: nginx-ui
build: .
image: bifeldy/nginx-ui:latest
# ports:
# - 8080:8080
volumes:
- D:/_data/_docker/nginx:/etc/nginx
networks:
- bifeldy-net

nginx:
container_name: nginx
image: nginx:latest
ports:
- 8888:80
volumes:
- D:/_data/_docker/nginx:/etc/nginx
networks:
- bifeldy-net

networks:

bifeldy-net:
name: bifeldy-net
external: true
Copy link
Owner

Choose a reason for hiding this comment

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

Hey @bifeldy, could you please remove this one? It's not generic since it's assumes that

  1. a drive D:/ is always the target to mount
  2. you are using your username as a network name

btw. everything that's in the repo need maintenance and I don't want to support on issues with docker-compose and windows.

I'm okay with adding it in a seperate section in the README.md to provide an example for people that are using windows.

Best David