Apache serve service from local host on subdomain - apache

I am trying to use Apache to serve multiple sites at the same time, the structure I want to obtain is composed by a main site at example.com and use the subdomains radarr.example.com and sonarr.example.com to access my Radarr and Sonarr servers.
The main site is hosted on machine1, I set up a virtual host using apache and certbot:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName example.com
WSGIDaemonProcess sflasksite user=www-data group=www-data threads=5
WSGIScriptAlias / /var/www/webapp/app.wsgi
<Directory /var/www/webapp>
WSGIProcessGroup sflasksite
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Require all granted
</Directory>
Alias /static /var/www/webapp/static
<Directory /var/www/webapp/static/>
Order deny,allow
Require all granted
</Directory>
ErrorLog /var/www/webapp/logs/error.log
CustomLog /var/www/webapp/logs/access.log combined
SSLCertificateFile /etc/letsencrypt/live/example.com-0002/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com-0002/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
The two servers I want to serve are on machine2, on the same network as machine1, how can I obtain the two services respectively on radarr.example.com and sonarr.example.com?
After some reading, I tried to use a Reverse Proxy, configuring a virtual host for each service as follows:
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerAlias radarr.example.com
ProxyPass / http://192.168.1.20:7878/
ProxyPassReverse / http://192.168.1.20:7878/
ErrorLog /var/www/radarr/logs/error.log
CustomLog /var/www/radarr/logs/access.log combined
</VirtualHost>
and alike for Sonarr.
However, when I navigate to radarr.example.com, I do not get the expected service but the main site.
How can I get the reverse proxy to work? Or should I switch to another strategy altogether?

Related

SOLVED: How to configure Apache2 with Reverse Proxy. Map an internal website to a folder of another (public) website on the same server

I have build a SPA and deployed it to my server. It is running on http://my-server:3000.
I then installed Apache2 and created a static page. This website is on the same server http://my-server:80 and is open to the Internet via a My-domain.
What I'm trying to accomplish now is to add a link on this static page (http://my-server/foo) which is redirected to http://my-server:3000 in such a way that the here deployed SPA can be run from this sub-folder.
I configured a new Virtual host in Apache2 with the following configuration:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName My-domain
ProxyRequests Off
ProxyHTMLEnable On
ProxyHTMLExtended Off
ProxyPreserveHost On
ProxyPass /foo/ http://my-server:3000/
<Location /foo/>
ProxyHTMLURLMap / /foo/
ProxyPassReverse http://my-server:3000/
SetOutputFilter INFLATE;DEFLATE
</Location>
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
LogLevel info
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Although the SPA is accessed and all the files are loaded the application will not start due to the error No match for URL in routes. I think it is due to the fact that the SPA is build to run in the root of a website and I'm now trying to run it in a sub-folder.
Does anyone know if this is possible? A solution would be appreciated much :-)
I found a solution which works for me :-)
Since I can use any prefix before My-domain like foo.My-domain, just found out recently, I changed the configuration for my Virtual host to this:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName foo.My-domain
ProxyRequests Off
ProxyHTMLEnable On
ProxyHTMLExtended Off
ProxyPreserveHost On
ProxyPass / http://my-server:3000/
<Location />
ProxyPassReverse http://my-server:3000/
SetOutputFilter INFLATE;DEFLATE
</Location>
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
LogLevel info
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
And because my SPA now is allowed to run in the root of a website it is working. :-)

How apache2 can deny connections to a domain which is not hosted

I am hosting website iplocation.io on a cloud server. I found a domain https://chrissloey.com/index.php which opens my website within it.
Now from what I understand, chrissloey.com has pointed it A record to my server ip and my apache2 server is not denying connection to it and allow's to open iplocation.io website content like its own.
I want apache2 to deny connections to any other domain and only allow my own domain to server content.
Attached is apache conf file for iplocation.io
<VirtualHost *:80>
ServerAdmin email#email.com
DocumentRoot /var/www/public_html
ServerName iplocation.io
ServerAlias www.iplocation.io
ErrorLog ${APACHE_LOG_DIR}/apache-error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/public_html>
Options FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName iplocation.io
ServerAdmin email#email.com
DocumentRoot /var/www/public_html
SSLEngine on
SSLCertificateFile /path-to-csr
SSLCertificateKeyFile /path-to-key
SSLCertificateChainFile /path-to-ca
<Directory /var/www/public_html>
Options FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
</IfModule
Looking at the two comments I think the combination makes most sense:
Configure httpd to respond with redirect (301) to all incoming requests. This could be done on the 'root' host.
Configure a virtualhost listening to your domain only, and this one would serve your real content only.
This will work unless the other site requests your content and then integrates it into their responses. But as you said someone else simply put up a DNS A record.

VirtualHost configuration issue

I have two apps I want to serve via port 80 in Apache on the same ip host. To do so, I have defined the following virtual hosts:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/var/www/wsgi/rest_api"
ServerName api
WSGIDaemonProcess rest_api user=gms threads=5
WSGIScriptAlias /api /var/www/wsgi/rest_api/rest_api.wsgi
WSGIPassAuthorization On
<Directory /var/www/wsgi/rest_api/rest_api>
Order deny,allow
Allow from all
Options +Indexes
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/www/extjs/cardiocatalogqt"
ServerName cardiocatalogqt
Alias /cardiocatalogqt /var/www/extjs/cardiocatalogqt
<Directory /var/www/extjs/cardiocatalogqt>
Options Indexes FollowSymLinks
AllowOverride None
Order Deny,Allow
Allow from all
</Directory>
</VirtualHost>
The problem is that only the first one in the list is being recognized (they both work independently). What am I missing to get both of these working together, independent of order?
EDIT
I am trying to avoid use of different server names due to a CORS authentication issue across domains (which includes host names and ports). All I want is two different paths as such to resolve accordingly: http://test.com/cardiocatalogqt and http://test.com/api.
Please create two different virtual host with different server names and different document root paths
<VirtualHost *:80>
ServerAdmin admin#test.com
ServerName test.com
ServerAlias www.test.com
DocumentRoot /var/www/test.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Also, add the server name into the hosts file.
mod_alias was what I wanted, ala http://httpd.apache.org/docs/2.2/mod/mod_alias.html
Works like a charm!
EDIT
More specifically, my config looks like this:
WSGIDaemonProcess rest_api user=gms threads=5
WSGIScriptAlias /api /var/www/wsgi/rest_api/rest_api.wsgi
WSGIPassAuthorization On
<Directory /var/www/wsgi/rest_api/rest_api>
Order deny,allow
Allow from all
Options +Indexes
</Directory>
<VirtualHost *:80>
DocumentRoot "/var/www/extjs/cardiocatalogqt"
ServerName cardiocatalogqt
Alias /cardiocatalogqt /var/www/extjs/cardiocatalogqt
<Directory /var/www/extjs/cardiocatalogqt>
Options Indexes FollowSymLinks
AllowOverride None
Order Deny,Allow
Allow from all
</Directory>
</VirtualHost>

How to configure different Virtual Hosts based on apache + php_cgi and apache+mod_php?

everybody.
I have a Cent OS 6.6 server with Apache + mod_php site (site1.local). I need to configure second site (site2.local) with php_cgi. So, I created a user, gave him permissions on www-folder, configured site1 as mod_php, created a phpinfo.php. Also, I installed php-cgi,and try to configure virtual hosts, works only first site, on the second site is error:
the requested url /cgi-bin/phpinfo.php was not found onthis server.
That's my configs:
cat /etc/httpd/conf/httpd.conf
<VirtualHost *:80>
ServerAdmin webmaster#site1.local
DocumentRoot /var/www/wwwmaster/site1.local
ServerName site1.local
ServerAlias www.site1.local
ErrorLog logs/site1.local-error_log
CustomLog logs/site1.local-access_log common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#site2.local
DocumentRoot /var/www/wwwmaster/site2.local
ServerName site2.local
ServerAlias www.site2.local
ScriptAlias /cgi_bin/ /usr/bin/php-cgi/
Action php-cgi /cgi-bin
AddHandler php-cgi php
<Directory /usr/bin/php-cgi>
Allow from all
</Directory>
<Directory "/var/www/wwwmaster/site2.local/">
<FilesMatch "\.php">
SetHandler php-cgi
</FilesMatch>
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order Deny,Allow
Allow from all
</Directory>
ErrorLog logs/site2.local-error_log
CustomLog logs/site2.local-access_log common
</VirtualHost>
What I've done wrong and how can I fix that?
You only have to uncomment the line that says NameVirtualServer *:80 in your apache config file.
If you want virtual server for more than one port, simply put as many NameVirtualServer *:[port number] in the apache config file as you need.

Why does port-based VirtualHost not work?

I'm trying to serve up two different Django apps on two separate ports. I have app1 on port 80 and app2 on port 8080. So what I'm expecting is that when I put example.com:80 into my browser, my request should get served up from app1, and when I put example.com:8080 into my browser, my request should get served up from app2. However, sometimes it will serve up my request from the wrong app. Then, after a few refreshes, it will sometimes switch. What's more, sometimes it will serve up from the correct app and then, after a few refreshes, switch to the wrong one. I know this isn't due to caching on the browser's end because I've also tried sending requests with curl from the machine and I get the same behavior. I can't understand why I'm getting this unexpected, nondeterministic behavior.
Here is my VirtualHost configuration:
<VirtualHost *:80>
ServerAlias *
ServerPath /app1/
WSGIScriptAlias /app1 /home/eyuelt/app1/app1/wsgi.py
Alias /app1/static /home/eyuelt/app1/staticfiles
<Directory /home/eyuelt/app1/app1>
<Files wsgi.py>
Order deny,allow
Require all granted
</Files>
</Directory>
<Directory /home/eyuelt/app1/staticfiles>
AllowOverride None
Order Deny,Allow
Require all granted
</Directory>
</VirtualHost>
Listen 8080
<VirtualHost *:8080>
ServerAlias *
ServerPath /app2/
WSGIScriptAlias /app2 /home/eyuelt/app2/app2/wsgi.py
Alias /app2/static /home/eyuelt/app2/staticfiles
<Directory /home/eyuelt/app2/app2>
<Files wsgi.py>
Order deny,allow
Require all granted
</Files>
</Directory>
<Directory /home/eyuelt/app2/staticfiles>
AllowOverride None
Order Deny,Allow
Require all granted
</Directory>
</VirtualHost>
I suspect this might be the problem:
http://httpd.apache.org/docs/2.2/vhosts/examples.html
This is what you want: You have multiple domains going to the same IP
and also want to serve multiple ports. By defining the ports in the
"NameVirtualHost" tag, you can allow this to work.
One or both of these could be the problem: If you try using
without the NameVirtualHost name:port or you
try to use the Listen directive, your configuration will not work.
Server example:
Listen 80
Listen 8080
NameVirtualHost 172.20.30.40:80
NameVirtualHost 172.20.30.40:8080
<VirtualHost 172.20.30.40:80>
ServerName www.example.com
DocumentRoot /www/domain-80
</VirtualHost>
<VirtualHost 172.20.30.40:8080>
ServerName www.example.com
DocumentRoot /www/domain-8080
</VirtualHost>
<VirtualHost 172.20.30.40:80>
ServerName www.example.org
DocumentRoot /www/otherdomain-80
</VirtualHost>
<VirtualHost 172.20.30.40:8080>
ServerName www.example.org
DocumentRoot /www/otherdomain-8080
</VirtualHost>