Closed CultofRobots closed 5 years ago
If you like, you can provide here the details for nginx and apache configuration. I will gladly integrate this in the wiki.
Except I haven't gotten it to work properly, though I only spent about 2 minutes on it and haven't had a chance to get back to it yet. Positive I had websocket proxypass wrong. If I do get around to it this weekend I'll be more than happy to post the details for at least apache.
Here's an entry for subdomain (mympd.example.com) on apache2. It's a lot more complicated to do it on example.com/mympd. I'll do one for nginx when I get around to setting it up on another system. Attachedtext file with the markdown: mympd_proxy.txt
To access mympd behind apache2 enable mod_proxy if not already enabled:
a2enmod mod_proxy
Create a virtual host and add the following:
ProxyRequests Off
ProxyPreserveHost on
ProxyVia On
<Location "/">
ProxyPass http://127.0.0.1:8080/
ProxyPassReverse http://127.0.0.1:8080/
</Location>
<LocationMatch "/ws/?">
ProxyPass ws://127.0.0.1:8080
ProxyPassReverse ws://127.0.0.1:8080
</LocationMatch>
To add basic password authentication create a new htpasswd file
sudo htpasswd -c <path/to/htpasswd/file> <username to access mympd>
Or append an existing htpasswd file
sudo htpasswd <path/to/htpasswd/file> <username to access mympd>
for example:
sudo htpasswd -c /etc/apache2/.htpasswds mympd
Then add the following to your mympd Location in your apache virtualhost configuration file
AuthType Basic
AuthName "Authentication Required" # or add any type of identifier you prefer
AuthUserFile <path/to/htpasswd/file> # for example /etc/apache2/.htpasswds
Require valid-user
for example:
<Location "/">
AuthType Basic
AuthName "Authentication Required" # or add any type of identifier you prefer
AuthUserFile <path/to/htpasswd/file> # for example /etc/apache2/.htpasswds
Require valid-user
ProxyPass http://127.0.0.1:8080/
ProxyPassReverse http://127.0.0.1:8080/
</Location>
See https://wiki.apache.org/httpd/PasswordBasicAuth for more information
To limit acces to mympd to the local network, add the following to the location directive adjusting for your own network:
Require host localhost
Require ip <ipaddress>
Require ip <ip range/netmask> # ex 192.168.1.0/24
See https://httpd.apache.org/docs/2.4/howto/access.html for more information
<VirtualHost *:80>
ServerName mympd.example.com
ProxyRequests Off
ProxyPreserveHost on
ProxyVia On
<Location "/">
Require host localhost
Require ip 192.168.1.0/24
AuthType Basic
AuthName "Authentication Required"
AuthUserFile /etc/apache2/.passwds/mympd
Require valid-user
ProxyPass http://127.0.0.1:8080/
ProxyPassReverse http://127.0.0.1:8080/
</Location>
<LocationMatch "/ws/?">
ProxyPass ws://127.0.0.1:8080
ProxyPassReverse ws://127.0.0.1:8080
</LocationMatch>
</VirtualHost>
Many thanks for this documentation. I created a wiki page: https://github.com/jcorporation/myMPD/wiki/Accessing-myMPD-through-Apache2
@jcorporation Please allow me to praise your job with this project, it's awesome!
Also, here's my nginx reverse proxy config for myMPD using sub_filter
, in case it helps anybody:
location /mympd/ {
[...]
proxy_set_header Accept-Encoding "";
sub_filter_types text/html text/css text/javascript text/xml application/x-javascript;
sub_filter_once off;
sub_filter '/css/' '/mympd/css/';
sub_filter '/js/' '/mympd/js/';
sub_filter '/assets' '/mympd/assets';
sub_filter '/api' '/mympd/api';
sub_filter '/ws' '/mympd/ws';
sub_filter '/player.html' '/mympd/player.html';
sub_filter 'href="/' 'href="/mympd/';
}
Thanks a lot. I added your configuration to a new wiki site: https://github.com/jcorporation/myMPD/wiki/Accessing-myMPD-through-Nginx
Wiki: Add section for nginx & apache reverse proxy
Should include the following:
Could also include example with limiting access to local network. For example, in apache
Require ip 192.168.1.0/24
Nothing fancy, just the basic "This is the minimal needed to make it work".
Related: #29