I spent some time to understand nginx.
try https://www.keycdn.com/support/nginx-location-directive
or https://nginx.org/en/docs/http/ngx_http_core_module.html#location
and more ...
My first post, my background:
After a long period w/o GNU/Linux, since I stopped using fli4l/eisfair,
I restarted several months ago with OMV6/Debian11, hardware details below, and clients with LMDE.
After organizing my backup strategy for the NAS-data with handmade cronjobs and rsync-scripts,
I am happy with the basics and this project.
To say thanks, I write a bit after experiencing nginx@OMV6,
to make it easier for others to get started and suffer directly .
Additionally my NAS shall do monitoring (only local/LAN/WiFi) with munin, which uses http:80, like OMV6 does.
My experience with LAMP is decades ago and vanished.
A good opportunity to deal with nginx as local (minimum set_header)
reverse-proxy (**ports**, **sub/domains**, **different paths**).
I red threads a lot, here and there. Below aAt the end you find the reasonable background for OMV6.
Start with "long story short":
nginx @ OMV6 to "manage several virtual hosts" on the same port:80, yet different to OMV6port:70
- Preliminary:
- Be aware what you are doing, as always when you are familiar with CLI.
- You may kick yourself out off the webGUI and more important, you touch the security of OMV6.
- YES, I tried to handle OMV6port:80 too, but I decided, NOT to deal with it (yet):
Code
omv-env set OMV_NGINX_SITE_WEBGUI_LISTEN_PARAMS " " # only necessary if OMV6port:80 omv-env get OMV_NGINX_SITE_WEBGUI_LISTEN_PARAMS OMV_NGINX_SITE_WEBGUI_LISTEN_PARAMS=' ' # an empty string resp. three blanks
- start with a check of OMV6/nginx configuration with ```cat``` or ```tail -5 /etc/nginx/sites-available/openmediavault-webgui```
- in webGUI-menue: System-Workbench change http:80 to http:70 i.e. if needed SSL/TLS httpS:443 to httpS:??? (not yet in trusted LAN)
- proof the change
```ls -al /etc/nginx/sites-available/openmediavault-webgui```
```tail -5 /etc/nginx/sites-available/openmediavault-webgui```
Code
} listen *:70 default_server; listen [::]:70 default_server; include /etc/nginx/openmediavault-webgui.d/*.conf; }
- in my example the directories at nginx-data location are
- create ```/etc/nginx/sites-available/80-vhosts``` as additional config file
Code
Display More#:70 Direct host for openmediavault-webgui # (free:80) # Default server configuration #:80 catch-all landing page is /usr/share/nginx/html/index.html server { listen 80 default_server; listen [::]:80 default_server; server_name _; root /var/www; index index.html index.htm index.nginx-debian.html; # index.php location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; } } #:80 server ### START ### server { listen 80; listen [::]:80; server_name nas.local 192.168.178.xx; # optional information, if without any letters root /var/www; index index.html index.htm index.nginx-debian.html; # index.php ## diabled while openmediavault:70 is used ## Subdirectory 1 for openmediavault:80 # (http://nas.local/openmediavault/) # location ^~ /openmediavault { # proxy_set_header Host $host; # proxy_pass http://127.0.0.1:81; # proxy_redirect off; # } # Subdirectory 2 for html:82 # (http://nas.local/html/) location ^~ /html { proxy_set_header Host $host; proxy_pass http://127.0.0.1:82; proxy_redirect off; } # Subdirectory 3 for munin:83 # (http://nas.local/munin/) location ^~ /munin { proxy_set_header Host $host; proxy_pass http://127.0.0.1:83; proxy_redirect off; } # Subdirectory 4 for web:84 # (http://nas.local/web/) # ln -s /srv/dev-disk.../web /var/www/web location ^~ /web { proxy_set_header Host $host; proxy_pass http://127.0.0.1:84; proxy_redirect off; } # Subdirectory 5 for xyz:85 # (http://nas.local/xyz/) } #:80 server ### END ### ## diabled while openmediavault:70 is used ##:81 Virtual host 1 for openmediavault # webGUI #server { # listen 81; # server_name 127.0.0.1; # location ^~ /openmediavault { # root /var/www; # uri is added # } #} #:82 Virtual host 2 for html # local web-pages server { listen 82; server_name 127.0.0.1; location ^~ /html { root /var/www; # uri is added } } #:83 Virtual host 3 for munin # server-monitoring server { listen 83; server_name 127.0.0.1; location ^~ /munin { root /var/www; # uri is added } } #:84 Virtual host 4 for web # webspace-mirror server { listen 84; server_name 127.0.0.1; location ^~ /web { root /var/www; # uri is added } } #:85 Virtual host 5 for xyz #
- create a relative symlink for the additional nginx-config file to ```sites-enabled```
- let nginx check the config ```nginx -t``` and re/load it ```nginx -s reload```
- try the vhosts, don't forget to clear browser cache and check the ```nginx/error.log``` parallel, ```tail -10 /var/log/nginx/error.log```
- if some vhosts work, others not, faults outside this config are possible, like file access rights. For processing dirs/files.html nginx needs permission rw-r-xr-x, try ```chmod -R 755 / 644```. Go back to 1., simplify, be patient and good luck.
background: nginx-plugin and OMV_NGINX_SITE_WEBGUI_LISTEN_PARAMS
OMV5 - Problem with nginx activating multiple virtual hosts due to missing "default_server" #620
#620 24 Feb 2020
That is why I tell people to NOT put the OMV nginx instance on the internet.
#848 13 Nov 2020
https://chrisjean.com/fix-ngin…8-address-already-in-use/
#1189 20 Jan 2022
^~ https://serverfault.com/questi…n-an-nginx-location-block
OMV6 nutzt den nginx-webserver ohne plugin, weil manche Anwender damit (große) Schwierigkeiten erlebten. Die Erreichbarkeit weiterer Seiten auf port:80 muss manuell eingerichtet werden. catch-all server block only once per port in the whole config @ /etc/nginx/sites-enabled Now solved with: Add environment variable OMV_NGINX_SITE_WEBGUI_LISTEN_PARAMS since
openmediavault (6.0.9-5) unstable; urgency=low
* Issue #1189: Add environment variable OMV_NGINX_SITE_WEBGUI_LISTEN_PARAMS
to be able to customize the nginx listen directive.
-- Volker Theile < @ openmediavault.org> Wed, 12 Jan 2022 19:53:08 +0100
You can disable adding 'default_server' option by
setting env variable with an empty string resp. three blanks:
omv-env set OMV_NGINX_SITE_WEBGUI_LISTEN_PARAMS " " # only necessary if OMV6port:80
omv-env get OMV_NGINX_SITE_WEBGUI_LISTEN_PARAMS
OMV_NGINX_SITE_WEBGUI_LISTEN_PARAMS=' ' # an empty string resp. three blanks
https://www.keycdn.com/support/nginx-location-directive
https://nginx.org/en/docs/http…core_module.html#location
####
# Regular expressions (RE) or literal strings can be used to define the modifier.
# location optional_modifier location_match { . . . }
#### optional_modifier
# No modifier at all means that the location is interpreted as a prefix.
# To determine a match, the location will now be matched against the beginning of the URI.
# ^~ Assuming this block is the best non-RE match, a carat followed by a tilde
# modifier means that RE matching will not take place.
#### location_match
# ist der Suchstring und bleibt erhalten bzw.
# wird komplett an das root-Verzeichnis angehängt.
####
Display More