NginxProxyManager / nginx-proxy-manager

Docker container for managing Nginx proxy hosts with a simple, powerful interface
https://nginxproxymanager.com
MIT License
22.62k stars 2.63k forks source link

Use nginx-proxy-manager as web server #280

Closed callebridholm closed 3 years ago

callebridholm commented 4 years ago

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.

jc21 commented 4 years ago

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.

callebridholm commented 4 years ago

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.

ikomhoog commented 4 years ago

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

neojp commented 4 years ago

@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!

fuzsh commented 3 years ago

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;
    }
  4. don't forget to run docker-compose up -d
  5. you can use it in a subdomain or main domain.
  6. have fun.
Jacob-Lasky commented 3 years ago

@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?

fuzsh commented 3 years ago

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

nandhakumargdr commented 3 years ago

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?

ikomhoog commented 3 years ago

@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 commented 3 years ago

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 commented 3 years ago

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.

ikomhoog commented 3 years ago

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.

DanielZsk commented 3 years ago

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:

ikomhoog commented 3 years ago

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;
    }
  5. click save
  6. 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.
  7. fill the txt file with some random text.
  8. go to the domain you entered in step one and add /test.txt
  9. you should now see the contents of that txt file (or download it depending on the browser(i think))
  10. profit???

I hope this helps

DanielZsk commented 3 years ago

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; }

Jacob-Lasky commented 3 years ago
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!

alakhpc commented 3 years ago

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:

jithinsisaac commented 3 years ago

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!

chaptergy commented 3 years ago

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

Casal0x commented 2 years ago

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

Jacob-Lasky commented 2 years ago

@Casal0x

The minimum lines I needed in the advanced section are the following:

location / {
   root /path/to/website/folder;
}

As long as you have an index.html within the folder you're pointing to then you should be good.

I use the NginxProxyManager in UnRAID through docker and these are my settings image

Just make sure that your container can see the folder you're using, and I haven't had problems with removing try_files

Let me know if this works.

SP3NGL3R commented 1 year ago

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?

This worked 99% perfectly for me too. Thank you. I opted for "nginx-static" instead of 1.1.1.1, just so it is a bit more self descriptive. But it still works. Now my problem is when I go to sub.site.com/folder/ it doesn't load the index.htm from the folder. It works at "/", just not at "/folder/". Any ideas there? I've tried a few things but they all don't work and I can't figure it out from the NGINX documentation. --thanks for the easy solution