nginx-proxy-manager icon indicating copy to clipboard operation
nginx-proxy-manager copied to clipboard

Use nginx-proxy-manager as web server

Open callebridholm opened this issue 6 years ago • 22 comments

Hi, I recently used apache2 at my Debian device as web server. Then I found this thing that helped my to publish several thing on other machines in my local network with SSL to the web. To still be able to publish things at my local machine I earlier use apache2 directly for I now use nginx-proxy-manager and point to localhost:8080 (I change port for apache2). is it possible to just replace apache2 with nginx-proxy-manager directly as the only webserver? I have problem with one application hosted on the same machine as nginx-proxy-manager when it act as proxy for apache2. I found that you can specify some local folders but still you need to point to some ip address somehow.

callebridholm avatar Jan 26 '20 18:01 callebridholm

Yep so you're requesting a Static site configuration and NPM doesn't support that yet. I'll keep this in mind when planning for the next major version.

jc21 avatar Jan 27 '20 23:01 jc21

Yep so you're requesting a Static site configuration and NPM doesn't support that yet. I'll keep this in mind when planning for the next major version.

Yes for example I want to replace a vhost in Apache2 pointing to /var/www/mysite/ with this proxy if possible to not need to run two web servers at the same machine.

callebridholm avatar Jan 28 '20 10:01 callebridholm

i did this a while ago, didnt know it should be impossible so nothing stopped me.

i added an environment path: /websites : /mnt/user/appdata/NginxProxyManager/websites

i set the details to 1.1.1.1:1 because i had to fill in everything.

and set the advance thing to

location / { root /websites; }

and then you get set it to a subdomain (websites for example), and just use it like websites.XXXXXX.com/index.html and the html page will show up

ikomhoog avatar Apr 10 '20 15:04 ikomhoog

@jc21 I would love to see this feature built-in. I will help if you have any pointers on how you would like to see this done.

@ikomhoog This worked for me. Thanks for the workaround!

neojp avatar Oct 21 '20 09:10 neojp

complete @ikomhoog answer, thanks to @ikomhoog . :+1:

  1. add volume like /opt/websites:/mnt/user/appdata/NginxProxyManager/websites
  2. set the details to 1.1.1.1:1 or everything you like.
  3. then in advance section add these lines:
root /mnt/user/appdata/NginxProxyManager/websites;
index index.html;
location / {
    try_files $uri /index.html /index.html;
}
  1. don't forget to run docker-compose up -d
  2. you can use it in a subdomain or main domain.
  3. have fun.

fuzsh avatar Oct 31 '20 14:10 fuzsh

@FaRzad-845 - Thanks for your input, I've been able to get it running however the CSS/JS on the site fails to load.

If I were to load the .html file, then everything is loaded without any problems.

However, when going to the site's URL, the only thing I see is the html site. Are there additional steps to getting the CSS and JS working?

Jacob-Lasky avatar Nov 05 '20 23:11 Jacob-Lasky

@Jacob-Lasky i use above snippet for react app and everything is okay. can you give more details on what exactly you do ?

fuzsh avatar Nov 06 '20 06:11 fuzsh

complete @ikomhoog answer, thanks to @ikomhoog . 👍

  1. add volume like /opt/websites:/mnt/user/appdata/NginxProxyManager/websites
  2. set the details to 1.1.1.1:1 or everything you like.
  3. then in advance section add these lines:
root /mnt/user/appdata/NginxProxyManager/websites;
index index.html;
location / {
    try_files $uri /index.html /index.html;
}
  1. don't forget to run docker-compose up -d
  2. you can use it in a subdomain or main domain.
  3. have fun.

Working for me, and how to apply the SSL certificate?

nandhakumargdr avatar Mar 02 '21 14:03 nandhakumargdr

@nandhakumargdr for me the SSL certificate just works like for a normal proxy, via the SSL tab of the nginx-proxy-manager "New/Edit Proxy Host" screen.

ikomhoog avatar Mar 02 '21 15:03 ikomhoog

as an update to the earlier config, I now use a shorter method(still the same steps as before, just a shorter version under the advance tab): this redirects mydomain.com to portfolio.mydomain.com but if I use mydomain.com/index.html it will return /websites/index.html

location = / {
return 301 https://portfolio.mydomain.com;
}
location / {
root /websites;
}

This is also useful if you want to download a file since it will just return the file instead of only returning index.html.

ikomhoog avatar Mar 02 '21 15:03 ikomhoog

So Im trying to migrate my SWAG setup over to this tool, its much easier to start up a proxy. I'm having a hard time following exactly what goes where to get this working as a simple webserver for my static webpages I'm hosting.

How do I fill out the entire Details tab? How do I fill out the entire Custom location tab and what is it signifying?

as an update to the earlier config, I now use a shorter method(still the same steps as before, just a shorter version under the advance tab): this redirects mydomain.com to portfolio.mydomain.com but if I use mydomain.com/index.html it will return /websites/index.html

location = / {
return 301 https://portfolio.mydomain.com;
}
location / {
root /websites;
}

This is also useful if you want to download a file since it will just return the file instead of only returning index.html.

flinkazoid avatar Mar 05 '21 00:03 flinkazoid

How do I fill out the entire Details tab? How do I fill out the entire Custom location tab and what is it signifying?

In the details tab you just fill in a subdomain, random ip and random port. This is because it has to be filled in in order to save the proxy.

I don't actually know the custom location tab, i haven't tried it, i always leave it blank. I fill in the advanced tab with nginx config code.

ikomhoog avatar Mar 05 '21 07:03 ikomhoog

I cant get it to work, especially the advance section underlines some parts in red and doesnt allow me to save it. Im a rook, any more pointers you could give me? Thanks in advance My volumes: volumes: - ./data:/data - ./letsencrypt:/etc/letsencrypt - ./localdirstaticcontent/publish/wwwroot:/mnt/user/appdata/NginxProxyManager/websites

DanielZsk avatar Mar 16 '21 12:03 DanielZsk

these are my volumes:

-v '/mnt/user/appdata/NginxProxyManager/data':'/data':'rw'
-v '/mnt/user/appdata/NginxProxyManager/letsencrypt':'/etc/letsencrypt':'rw' 
-v '/mnt/user/Websites/':'/websites':'rw'

I made Websites share for this. I gave nginx a new path named /websites Whereas you have given it '/mnt/user/appdata/NginxProxyManager/websites' Now if you want to refer to that folder you have to use '/mnt/user/appdata/NginxProxyManager/websites' where I can use /websites.

So it might be better to just change it to the same for simplicity(not an expert so there might be something wrong with this)

I dont get red lines when typing in the advance section and even when putting in garbage text i can still save it. It wont work ofcourse and shows the proxy as "offline" with a red dot instead of a green one. But that shouldnt be the issue

Did you follow the earlier steps of filling in the first tab "details" where it asks the domain names, IP and Port? just fill in a random IP/Port just because you cannot save if you miss these.

Also just for an update to my earlier guide thingy:

  1. Add a volume to the container like /websites : /mnt/user/appdata/NginxProxyManager/websites
  2. Create a new Proxy Host in the NPM UI, and fill in the domain names you want to use.
  3. Add an IP and Port simply because it wont save if you dont, it wont actually be used, i use 1.1.1.1:1 for this example.
  4. Go to the advanced tab in the new proxy host window and paste this script:
location / {
root /websites;
}
  1. click save
  2. put a text file named test.txt into the directory you assigned at step 1, this is /mnt/user/appdata/NginxProxyManager/websites in my example.
  3. fill the txt file with some random text.
  4. go to the domain you entered in step one and add /test.txt
  5. you should now see the contents of that txt file (or download it depending on the browser(i think))
  6. profit???

I hope this helps

ikomhoog avatar Mar 16 '21 13:03 ikomhoog

You are a gentleman! I owe you a biertje. Im new to this topic and you taking the time to break it down into simple steps helps me tremendously.

An interesting tidbit I have found, in case someone else has the same issue with SPAs: I tried to make the above work with a single page app (Blazor, however applies for ReactJs as well), Nginx's route always overwrote the router of the apps, therefore I kept receiving an error if I didnt start at /index.html. However, the solution is to force all requests through the index page, hence forcing them to go through the js router of the framework. You need to add: "try_files $uri $uri/ /index.html" . I could not add this in the advanced tab for some reason, it was underlined and wouldn't let me save it, however if you manually add the line into the datavolume/nginx/proxy_host/1.conf, it works like magic! No idea why it wont let me add this line in the GUI though...my file now looks like (not sure if this will persist, however it should as long as the volume is kept):

------------------------------------------------------------

localhost

------------------------------------------------------------

server { set $forward_scheme http; set $server "1.1.1.1"; set $port 80; listen 80; listen [::]:80; server_name localhost; access_log /data/logs/proxy_host-1.log proxy; location / { root /websites; index index.html index.htm; try_files $uri $uri/ /index.html; }

DanielZsk avatar Mar 16 '21 13:03 DanielZsk

1. add volume like
   `/opt/websites:/mnt/user/appdata/NginxProxyManager/websites`

2. set the details to 1.1.1.1:1 or everything you like.

3. then in advance section add these lines:
root /mnt/user/appdata/NginxProxyManager/websites;
index index.html;
location / {
    try_files $uri /index.html /index.html;
}
1. don't forget to run `docker-compose up -d`

2. you can use it in a subdomain or main domain.

3. have fun.

@FaRzad-845 - apologies for such a huge delay. Your instructions here worked great for me, with one change.

I needed to make sure that "cache assets" was turned off. Otherwise, I cannot load the CSS for some reason.

Thanks for this snipped!

Jacob-Lasky avatar Mar 17 '21 14:03 Jacob-Lasky

complete @ikomhoog answer, thanks to @ikomhoog . 👍

  1. add volume like /opt/websites:/mnt/user/appdata/NginxProxyManager/websites
  2. set the details to 1.1.1.1:1 or everything you like.
  3. then in advance section add these lines:
root /mnt/user/appdata/NginxProxyManager/websites;
index index.html;
location / {
    try_files $uri /index.html /index.html;
}
  1. don't forget to run docker-compose up -d
  2. you can use it in a subdomain or main domain.
  3. have fun.

Thanks! this works although I'm unable to get the force ssl option to work when doing so.

EDIT: I was able to get force ssl to work by changing some stuff:

  • set scheme to https
  • set forward hostname to the domain itself
  • set port to 443
  • Then modify the advanced config to be as below
if ($scheme = http) {
        return 301 https://$server$request_uri;
    }
root /mnt/user/appdata/NginxProxyManager/websites;
index index.html;
location / {
    try_files $uri /index.html /index.html;
}

This seems to be working so far.

jepcd avatar Mar 25 '21 06:03 jepcd

This is how i sorted this out, might not be the best option:

Installed & ran apache2 web server to listen to port 8081 instead of port 80, Then went to NPM and made a reverse proxy for xyz.domain.com to point to IP:8081. It works well for a single static site!

Can someone help if i want to do a virtual host thing? i.e. multiple websites to be opened up via single reverse proxy. I have not understood the solution given over here, would be grateful if someone can help with screenshots!

jithinsisaac avatar Apr 28 '21 01:04 jithinsisaac

Duplicate of https://github.com/jc21/nginx-proxy-manager/issues/58

chaptergy avatar May 11 '21 19:05 chaptergy

i tryed everything still getting 403 without try_files $uri /index.html /index.html; with this line i'm getting 500 any help pls @farzad-845 @jc21

Casal0x avatar Aug 26 '22 18:08 Casal0x