Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
sailing:nginx [2023/12/01 09:00] – [NGINX main configuration] willy | sailing:nginx [2024/02/01 07:00] (current) – removed willy | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | Prev to: [[sailing: | ||
- | Next to: [[sailing: | ||
- | |||
- | ---- | ||
- | ====== The Reverse Proxy concept ====== | ||
- | |||
- | Most of the tools described in these pages have web-based interfaces. It is **not** a good idea to access them directly for quite many reasons: | ||
- | * Scalability, | ||
- | * Security, since the tools don't come with a fully featured web server | ||
- | * Access control, since the tools don't come with a fully featured web server | ||
- | * Configuration, | ||
- | * Organization, | ||
- | |||
- | In other words, you want a reverse-proxy even if you are going to use this setup only from inside your home. More so, if you plan to have remote access, a reverse-proxy is a must. But what is a reverse-proxy? | ||
- | |||
- | There are lots of possible software to use. Basically any web server can act as a reverse proxy. Some are more suited than others, and my choice is on NGINX for a few reasons: | ||
- | * Much easier than [[https:// | ||
- | * Much lighter and less features full than Apache | ||
- | * More complex and more features than [[https:// | ||
- | * Fully integrated in [[https:// | ||
- | * I don't personally know how to setup other similar tools | ||
- | |||
- | In general NGINX is fully featured but still very lightweight and secure HTTP server that shines as reverse-proxy. If you need to add more features, like [[https:// | ||
- | |||
- | In order for a service to operate correctly behind a reverse proxy, it needs to support at least the // | ||
- | |||
- | The // | ||
- | |||
- | The authentication pass-trough is great, but it's even less supported by services. It will allow your nginx authentication to get picked up by the service and used without the need for a double authentication, | ||
- | |||
- | |||
- | ===== Installing NGINX ===== | ||
- | NGINX installation on the home server is pretty straightforward, | ||
- | |||
- | So create the file **/ | ||
- | < | ||
- | app-misc/ | ||
- | www-servers/ | ||
- | </ | ||
- | |||
- | (the first line is needed at the time of writing this page, YMMV) | ||
- | |||
- | Note: you might want to tweak the second line to your needs, see the [[https:// | ||
- | |||
- | A brief explanation of the above USE flags: | ||
- | * // | ||
- | * //sub// is used to allow substitutions inside the pages proxied, to fix web applications that don't play well with reverse-proxies | ||
- | * //gunzip// is used to unzip the requests and let the //sub// module works also on compressed requests | ||
- | |||
- | Now install nginx: | ||
- | <code bash> | ||
- | > emerge -v nginx | ||
- | </ | ||
- | |||
- | ==== NGINX pam_auth ==== | ||
- | |||
- | I think it's nice that with NGINX you can authenticate your users directly with your home server users. This means you don't need to add a second set of users, and that the users will only need one password, and no sync is required between HTTP users and server users. This is achieved using the **pam_auth** module on Linux. You have already built nginx with pam_auth support, but you need to configure it. | ||
- | |||
- | Create the file **/ | ||
- | < | ||
- | auth required pam_unix.so | ||
- | account required pam_unix.so | ||
- | </ | ||
- | |||
- | |||
- | ==== NGINX main configuration ==== | ||
- | |||
- | You need two different NINX configurations. One facing the home network, which will serve on HP only, and one facing the external world, which will serve HTTPS only with HTTP as a redirect to HTTPS. | ||
- | |||
- | NGINX is very flexible in configuration, | ||
- | |||
- | The main configuration file is located at **/ | ||
- | <code nginx> | ||
- | server { | ||
- | # Home facing server, HTTP only | ||
- | listen 127.0.0.1: | ||
- | server_name 192.168.0.1; | ||
- | |||
- | include " | ||
- | |||
- | access_log / | ||
- | error_log / | ||
- | } | ||
- | |||
- | server { | ||
- | # remote facing server, HTTPS | ||
- | server_name my_remote_server_name; | ||
- | auth_pam " | ||
- | auth_pam_service_name " | ||
- | |||
- | include " | ||
- | |||
- | access_log / | ||
- | error_log / | ||
- | |||
- | listen 127.0.0.1: | ||
- | ssl_certificate / | ||
- | ssl_certificate_key / | ||
- | include / | ||
- | ssl_dhparam / | ||
- | |||
- | location .well-known/ | ||
- | auth_pam off; | ||
- | autoindex on; | ||
- | } | ||
- | |||
- | } | ||
- | |||
- | |||
- | server { | ||
- | # remote facing server, HTTP to HTTPS redirection | ||
- | listen 8080; | ||
- | access_log / | ||
- | error_log / | ||
- | return 301 https:// | ||
- | } | ||
- | </ | ||
- | |||
- | I will walk you trough it a bit. | ||
- | |||
- | You have one simple section for the home server: it listen on port 80 and logs to some specific home only files. I choose not to use HTTPS inside the home network because it would be complicated to automatically generate the required certificates. If you still want HTTPS on the home side, you should use self-signed certificates, | ||
- | |||
- | The remote HTTP server is even simpler: just a redirect to the remote HTTPS server, listening on port 8080 since port 80 is already taken by the home server. You never, ever, want to go not encrypted on the outside world. The remote HTTPS server is on port 8443 and adds all the specific HTTPS certificate stuff. Do not bother with it yet, i will explain a bit more later on. | ||
- | |||
- | Please note that due to the HTTPS certificates (which at this point are still to be created) you cannot yet start NGINX. | ||
- | |||
- | You can see that i used the **include** directive to point to a common **folders/ | ||
- | <code nginx> | ||
- | # This might be needed to direct upload of NZB files | ||
- | client_max_body_size 200M; | ||
- | # This is required sometimes by Deluge web GUI giant cookies | ||
- | large_client_header_buffers 4 32k; | ||
- | |||
- | # Here you will put your dashboard | ||
- | root / | ||
- | |||
- | # Specific service configurations | ||
- | include " | ||
- | include " | ||
- | include " | ||
- | include " | ||
- | include " | ||
- | include " | ||
- | include " | ||
- | include " | ||
- | include " | ||
- | include " | ||
- | include " | ||
- | </ | ||
- | |||
- | As you can see, beside a few settings on top, it includes each service specific config as a separate file. This will give you lots of flexibility in adding or removing single services. The content of each specific service config file will be described in each service page. | ||
- | |||
- | The //root// directive is where you will need to put your dashboard to put all services together in a nice linked page, more details on this later on. | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | ==== Generate SSL certificates for HTTPS ==== | ||
- | |||
- | |||
- | |||
- | ---- | ||
- | Next to: [[sailing: | ||
- | |||
- | Prev to: [[sailing: |