[How to] Integrate Apache2 Subsonic 4.1 Ubuntu server

Tutorials, tips and tricks.

Moderator: moderators

[How to] Integrate Apache2 Subsonic 4.1 Ubuntu server

Postby nipar » Fri Nov 12, 2010 7:40 am

After 2 days of searching, trying things and not being pleased with the results I finally came up with this. It gets around the problem of external players not working properly.
I hope this helps :)

My Setup:
Ubuntu Server 8.04 LTS
Apache 2.2.14 configured not as localhost but as server01.mysite.dyndns-web.com (be careful, but take a look at
Code: Select all
hostname --help
if you're interested)
Subsonic 4.1 from subsonic-4.1.deb which does run as localhost:4040
(note: the .deb file install Jetty as the java server, not Tomcat. However this should make no difference when following this guide)
subsonic.sh SUBSONIC_CONTEXT=/subsonic

----purpose:
to change the browser URL from: http://mysite.somewhere.com:4040/subsonic
to: http://mysite.somewhere.com/subsonic
as if no port change happened. the end result is an internal proxy request the client never sees.


--------------install mod_rewrite and mod_proxy (all)
ssh into your server and become root
Code: Select all
sudo su


Note: most of the things you need to do here require you to be root.

Code: Select all
apt-get install libapache2-mod-proxy-html


rewrite and proxy were actually already included in my server install

-------------enable mod_rewrite and mod_proxy*

Code: Select all
a2enmod rewrite


Code: Select all
a2enmod proxy*



--------modify /etc/apache2/httpd.conf and add before any virtual hosts
Code: Select all
nano /etc/apache2/httpd.conf

Add these lines:
Code: Select all
RewriteEngine on
RewriteRule ^/subsonic(.*) http://mysite.dyndns-web.com:4040/subsonic$1 [P]




----------modify /ect/apache2/mods-enabled/proxy.conf
Code: Select all
nano /ect/apache2/mods-enabled/proxy.conf

comment out:
Code: Select all
#Deny from all


Note: apparently this is not dangerous if ProxyRequest is never turned on.
Any attempt to use the proxy to masquerade as you by malicious scripting or hacking
would not succeed as all proxy requrests are forwarded only to the server/application you specify.
Make SURE ProxyRequest is OFF
If your server is not fully secured, proxy requests can be made to look like it's your server doing all kinds of bad stuff.
---------modify virtual host file /etc/apache2/sites-enabled/000 - default
Code: Select all
nano /etc/apache2/sites-enabled/000-default

First line after <Virtual host *:80> copy and paste the followingt:
Code: Select all
# Without these 2 lines Apache2 does not pass on the Rewrite statements from httpd.conf
# to ANY Virtual Hosts. To enable Rewrite in ALL Virtual Hosts place this in ALL Virtual Host files.

RewriteEngine On
RewriteOptions Inherit

Directly below that add:
Code: Select all
ProxyPassReverse /subsonic http://mysite.dyndns-web.com:4040/subsonic


(Note: you do NOT need ProxyPass, only ProxyPassReverse)

-------reload apache (not restart)
Code: Select all
service apache2 force-reload


----- or
reboot the system

:D hope you had fun.

P.S. Let me know how you made out. And if I left something out.
nipar
 
Posts: 19
Joined: Fri Nov 12, 2010 6:07 am

Postby p4madeus » Fri Feb 25, 2011 3:13 pm

Any idea how to do this on Mac OS X? :?:
p4madeus
 
Posts: 8
Joined: Thu Jul 15, 2010 4:02 am

Postby jaquense » Thu Apr 07, 2011 4:31 pm

Always good to see documentation!

I have a very similar setup, tho I am using mod_jk instead of proxyPassReverse; leaving the connection handling all to Apache, as opposed to letting tomcat function as a full blown web server, for one host and Apache handle the rest of my site.

I doubt there is much of performance difference between the two methods but since I use Apache to host the rest of my sub-domains I find it easier to just handle all of the virtual hosts in Apache and in the case of java apps have those Apache hosts "Mount" tomcat
jaquense
 
Posts: 47
Joined: Tue Dec 28, 2010 7:06 pm

Zentyal - Ubuntu error

Postby SgtWirehead » Mon Apr 25, 2011 2:55 am

I'm using Zentyal, bassed on ubuntu. After following these instructions i get the errors below.

zentyal$ service apache2 force-reload
Syntax error on line 1 of /etc/apache2/httpd.conf:
Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
...fail!

zentyal:~$ service apache2 force-reload
Syntax error on line 3 of /etc/apache2/sites-enabled/000-default:
Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
SgtWirehead
 
Posts: 1
Joined: Mon Apr 25, 2011 2:21 am

Re: Zentyal - Ubuntu error

Postby jaquense » Mon Apr 25, 2011 5:56 pm

SgtWirehead wrote:I'm using Zentyal, bassed on ubuntu. After following these instructions i get the errors below.

zentyal$ service apache2 force-reload
Syntax error on line 1 of /etc/apache2/httpd.conf:
Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
...fail!

zentyal:~$ service apache2 force-reload
Syntax error on line 3 of /etc/apache2/sites-enabled/000-default:
Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration


in your /etc/apache2/mods-enabled directory do you see a rewrite.load file? It sounds like you don't have mod_rewrite installed. in a console type
Code: Select all
sudo a2enmod rewrite

that should enable the mod (it creates a symlink from the rewrite mod in mods-available to mods-enabled). then just restart the server and see if the error occurs
jaquense
 
Posts: 47
Joined: Tue Dec 28, 2010 7:06 pm

Postby Tehrasha » Sun Jul 17, 2011 8:17 am

I am trying to do something similar with apaches, except my subsonic install is not on the same machine as my webserver.

So I need to somehow proxy http://webserver/subsonic into http://streamer:4040/

Using lines from your post above, I have it working from within my home network, but users on the internet are seeing my home subnet in the URL, and thus failing to connect.

Shouldnt the proxy make the rerouting at my end transparent?
User avatar
Tehrasha
 
Posts: 2
Joined: Thu Apr 07, 2011 10:26 pm

Postby siggma » Wed Jul 20, 2011 5:55 pm

There really is no reason to use Apache to serve subsonic. The jetty server that comes with it works fine. What you do need to do is specify an IP address for each virtual machine in apache so it only binds to that/those addresses. Then edit the subsonic config and specify the ip address you registered with DNS for subsonic and set port to 80.

Mine works fine and I run Apache and subsonic simultaneously. It's also more efficient to run subsonic using the jetty server rather than apache because apache has to pass each request to an external java server like tomcat or jetty anyway so it adds complexity and overhead for no reason. You can also run it under tomcat the same way as jetty, just configure apache and tomcat so they only bind to specific addresses and they work fine together as long as they each have a separate IP address.Its called an "IP based virtual host". The jetty server then acts like a virtual host with a separate IP address.

subsonic.trbailey.net is a jetty based subsonic server
www.trbailey.net is my home web server site

Both run under the same OS on the same hardware (Debian Linux)

If anyone is interested I can post details on how I got apache to only use specific IP addresses.
siggma
 
Posts: 2
Joined: Wed Jul 20, 2011 5:44 pm

Postby siggma » Wed Jul 20, 2011 7:18 pm

Here is an easy HOW TO to run Apache and jetty together on the same server:

First register a hostname with your DNS provider for subsoinc. Use an A record and supply a unique public IP address. This cannot be an IP address used by any other server or service on your server. It can only be used by subsonic. Test your hostname registration using nslookup or dig or some other dns tool. Linux Example:

[root@moya]
~ $ dig subsonic.trbailey.net

; <<>> DiG 9.6-ESV-R4 <<>> subsonic.trbailey.net
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 55783
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;subsonic.trbailey.net. IN A

;; ANSWER SECTION:
subsonic.trbailey.net. 790 IN A XXX.XXX.XXX.XXX

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Wed Jul 20 12:13:34 2011
;; MSG SIZE rcvd: 55



Now that you have a working hostname start by editing /etc/apache2/ports.conf. Make sure there is a line for each IP address you want Apache to respond to. Only add lines you want apache to bind to here or it might interfere with subsonic. Typically there is only one IP address for apache unless you are using IP based virtual hosts.

Listen xxx.xxx.xxx.xxx:80
Listen xxx.xxx.xxx.xxx:80



Open your virtual host files usually located in /etc/apache2/sites-enabled/

Start with 000-default. Add a line for the specific IP address for this virtual host. The "NameVirtualHost" directive below must have a matching IP address in ports.conf.

<VirtualHost xxx.xxx.xxx.xxx:80>
DocumentRoot /var/www/
NameVirtualHost xxx.xxx.xxx.xxx:80

Edit any remaining virtual host config files and do the same.

Restart Apache:
/etc/init.d/apache2 restart

Now edit /etc/default/subsonic.conf

SUBSONIC_ARGS="--host=xxx.xxx.xxx.xxx --port=80"

Make sure the subsonic IP you use is not mentioned in any apache virtual host or in the ports.conf above.

/etc/init.d/subsonic restart

Test your new subsoic server.
siggma
 
Posts: 2
Joined: Wed Jul 20, 2011 5:44 pm

Postby switch81 » Wed Aug 03, 2011 10:48 pm

Thanks for the great tutorial, I think I got it working.. but I had a few questions...

Right now i can access subsonic using:
http://mydomain.com:8080/subsonic
or
http://mydomain.com/subsonic

but when I use the latter, it just forwards me back to mydomain.com:8080/subsonic.

This causes me problems as my work blocks port 8080 and I can't access my music. Did I do something wrong? When I look at the Subsonic demo, it looks like the url does not simply get "forwarded", but instead it's as if all subsonic services are seen on port 80 (i.e. i see the url http://subsonic.org/demo/index.view, not http://subsonic.org:8080/demo/index.view).

Any help is greatly appreciated!!
switch81
 
Posts: 4
Joined: Wed Aug 03, 2011 10:45 pm

Postby switch81 » Thu Aug 04, 2011 1:27 am

switch81 wrote:Thanks for the great tutorial, I think I got it working.. but I had a few questions...

Right now i can access subsonic using:
http://mydomain.com:8080/subsonic
or
http://mydomain.com/subsonic

but when I use the latter, it just forwards me back to mydomain.com:8080/subsonic.

This causes me problems as my work blocks port 8080 and I can't access my music. Did I do something wrong? When I look at the Subsonic demo, it looks like the url does not simply get "forwarded", but instead it's as if all subsonic services are seen on port 80 (i.e. i see the url http://subsonic.org/demo/index.view, not http://subsonic.org:8080/demo/index.view).

Any help is greatly appreciated!!


I found and followed the instructions here: http://blog.lundscape.com/2009/05/confi ... th-apache/

and everything works fine now!! :D :D
switch81
 
Posts: 4
Joined: Wed Aug 03, 2011 10:45 pm


Return to Tutorials

Who is online

Users browsing this forum: No registered users and 11 guests