# Uibuilder and nginx

**URL:** https://discourse.nodered.org/t/uibuilder-and-nginx/77628
**Category:** General
**Tags:** security, uibuilder
**Created:** [16 April 2023 11:49 UTC](https://discourse.nodered.org/t/uibuilder-and-nginx/77628 "2023-04-16T11:49:56Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Manuel\_o](https://avatars.discourse-cdn.com/v4/letter/m/977dab/32.png) [@Manuel\_o](https://discourse.nodered.org/u/Manuel_o)
#### Post date: [16 April 2023 11:49 UTC](https://discourse.nodered.org/t/uibuilder-and-nginx/77628/1 "2023-04-16T11:49:57Z")

</div>

Hello.

I am experimenting with uibilder nginx. To install nginx i follow this guide from:

> **[NGINX & Proxying Node RED](https://github.com/TotallyInformation/node-red-contrib-uibuilder/wiki/NGINX-&-Proxying-Node-RED)**
>
> Easily create data-driven web UI's for Node-RED using any (or no) front-end framework. - TotallyInformation/node-red-contrib-uibuilder

I tried to test nginx with a very simple node. i created a simple uibilder npde that has the URL  
myserverip:1880/test.

My second step was to create a user and a password with; sudo htpasswd -c /etc/apache2/.htpasswd user1. I verified, that there is a file htppasswd and that there is a user1:pw in it

Now i created a new conf.d in at /etc/nginx/conf.d#. in this i entered:

```auto
server {
  listen 80;
  server_name <my server ip>;

  location /test {
  auth_basic "Restricted";
  auth_basic_user_file /etc/apache2/.htpasswd;
  proxy_pass http://localhost:1880/;
  proxy_set_header Host $host;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}

```

I expected that now when i enter my server ip. i will be redirected to myserverip:1880/test and asked for a pasword.

Sorry when this are noob-questions. I am a the beginning of this journey

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [16 April 2023 12:05 UTC](https://discourse.nodered.org/t/uibuilder-and-nginx/77628/2 "2023-04-16T12:05:38Z")

</div>

> [@Manuel\_o](#):
>
> Sorry when this are noob-questions. I am a the beginning of this journey

No problem, it is a fairly gnarly journey to begin with.

You might want to try the uibuilder docs for a more up-to-date and detailed version of the WIKI.

[How to use NGINX as a reverse proxy with TLS and identity authentication (totallyinformation.github.io)](https://totallyinformation.github.io/node-red-contrib-uibuilder/#/uib-security-nginx)

Pay particular attention to slashes in your location, it is possible that you need a trailing slash. Also note that you have to proxy websockets as well which is missing in your example.

---

<div class="post-metadata">

### Author: ![Manuel\_o](https://avatars.discourse-cdn.com/v4/letter/m/977dab/32.png) [@Manuel\_o](https://discourse.nodered.org/u/Manuel_o)
#### Post date: [16 April 2023 13:18 UTC](https://discourse.nodered.org/t/uibuilder-and-nginx/77628/3 "2023-04-16T13:18:49Z")

</div>

thank you.

its much more complex than i thought. but u will try it.

but do i assume it correct, if i just want to test (the not secure) http redirect of my uibuilder test node (myip:1880/test/), my example settings above should be enough? Or do i have also configure node red websocket-proxy-stuff?

What i am asking myselft: in my directory **/etc/nginx/conf.d** i have 2 files now:  
conf.d AND default.conf

conf.d was edited by me to :

> server {  
> listen 80;  
> server\_name myServerIP;
> 
> location /test/ {  
> auth\_basic "Restricted";  
> auth\_basic\_user\_file /etc/nginx/.htpasswd;  
> proxy\_pass [http://localhost:1880/](http://localhost:1880/);  
> proxy\_set\_header Host $host;  
> proxy\_set\_header X-Real-IP $remote\_addr;  
> proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
> }
> 
> }

What i understand should "server\_name" be my ip adress of my linux server?  
.htpasswd exists with a user in the right directory.  
i also tested different cominations with Trailing Slashes for the soruce of the htppasswd and location

thank you again and sry

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [16 April 2023 14:01 UTC](https://discourse.nodered.org/t/uibuilder-and-nginx/77628/4 "2023-04-16T14:01:30Z")

</div>

> [@Manuel\_o](#):
>
> its much more complex than i thought

It is complex but you only have to do the hard bit once. After that, it is pretty simple. BTW, I have my settings split into different parts because there are things like security settings that need to be re-specified in different sections if you are handling more than 1 location. I've shared the full set before I think here in the forum.

> [@Manuel\_o](#):
>
> but do i assume it correct, if i just want to test (the not secure) http redirect of my uibuilder test node (myip:1880/test/), my example settings above should be enough? Or do i have also configure node red websocket-proxy-stuff?

Well, it should redirect but it won't work correctly. So you will get a page shown but it will only partly work.

> [@Manuel\_o](#):
>
> What i understand should "server\_name" be my ip adress of my linux server?

I don't think you need the server name at all if you are just using IP addresses. Not 100% certain since I use a DNS domain name and so the server name looks like: `.example.com` (note the leading dot).

I also have 2 server sections, one listening on `listen *:80 default_server;` and the other on `listen *:443 ssl default_server;`. The first redirects to the 2nd.

I also simply have a `location / { ...` so that everything is proxied. Then I have sub-locations such as this for the editor:

```auto
  # Proxy the Node-RED Editor https://my.public.domain/red/ to http://localhost:1880/red/
  location /red/ {
    
    # ==> Of course, you could have a separate auth here! <==

    # Reverse Proxy for websockets
    include /etc/nginx/conf.d/includes/common_ws_proxy_headers.conf;

    # Reverse Proxy
    proxy_pass https://localhost:1880/red/; # <== CHANGE TO MATCH THE EDITOR's URL
    
    # Tell upstream which proxy was used
    proxy_set_header X-JK-Proxy "RED";
    # Tell client which proxy was used (not really all that useful)
    add_header X-JK-Proxy "RED";

}

```

The custom headers are useful because it lets you detect if the correct proxy has been applied.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [15 June 2023 14:02 UTC](https://discourse.nodered.org/t/uibuilder-and-nginx/77628/5 "2023-06-15T14:02:12Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
