Apache Virtual Host with path - apache

I am deploying a Rails app with Phusion passenger and Apache HTTPD, to do that I have to create a virtual host in Apache to associate the root of my app. And this process is successful, effectively my app is running, but my problem is that I have to do this run in a path of my domain, such as "mydomain.com/railsapp".
I tried this configurations and all failed.**
Configuration 1
ServerAdmin admin#mydomain.com
ServerName mydomain.com/railsapp
RailsEnv production
RailsBaseURI /app
DocumentRoot /var/www/rails/app/public
<Directory /var/www/rails/app/public>
AllowOverride all
Options -MultiViews
#Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Configuration 2
ServerAdmin admin#mydomain.com
ServerName mydomain.com
ServerPath /railsappp
RailsEnv production
RailsBaseURI /app
DocumentRoot /var/www/rails/app/public
<Directory /var/www/rails/app/public>
AllowOverride all
Options -MultiViews
#Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Configuration 3
ServerAdmin admin#mydomain.com
ServerName mydomain.com
ServerAlias mydomain.com/railsappp
RailsEnv production
RailsBaseURI /app
DocumentRoot /var/www/rails/app/public
<Directory /var/www/rails/app/public>
AllowOverride all
Options -MultiViews
#Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Does Anyone have idea how to do that?

Use ServerName as my domain.com and make use of ProxyPass and ProxyPassReverse directive to redirect /railsapp to desired location.... Read more about reverse proxy..

Related

My website URL with www shows the correct content but shows the Apache2 Ubuntu Default page without www. How do I correct this?

I followed the How To Deploy a Flask Application on an Ubuntu VPS
and How To Install the Apache Web Server on Ubuntu 20.04
from Digital Ocean where my hosting is. I have two type A DNS records set up where the hostname is my URL with www and my URL without it, that direct to the value of my public IP.
I can change which address shows the correct information by changing ServerName to either my public IP, my website with www, or my website without www. How can I make it so that www.mywebsite.com and mywebsite.com both show correctly? A redirect surely can't be the right answer?
Here is the conf file: /etc/apache2/sites-available/FlaskApp.conf
<VirtualHost *:80>
ServerName www.mywebsite.com
ServerAdmin admin#mywebsite.com
WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi
<Directory /var/www/FlaskApp/FlaskApp/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/FlaskApp/FlaskApp/static
<Directory /var/www/FlaskApp/FlaskApp/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I tried adding a permanent redirect it didn't work.
<VirtualHost *:80>
ServerName www.mywebsite.com
Redirect permanent / http://mywebsite.com/
ServerAdmin admin#mywebsite.com
WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi
<Directory /var/www/FlaskApp/FlaskApp/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/FlaskApp/FlaskApp/static
<Directory /var/www/FlaskApp/FlaskApp/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
For anyone else with this problem I found a solution by adding a server alias:
<VirtualHost *:80>
ServerName www.mywebsite.com
ServerAlias mywebsite.com
ServerAdmin admin#mywebsite.com
WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi
<Directory /var/www/FlaskApp/FlaskApp/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/FlaskApp/FlaskApp/static
<Directory /var/www/FlaskApp/FlaskApp/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Set a default Virtual Host in Apache using Debian 10

I have a little problem.
I have a VPS configured with Apache, I have 2 VH, one is mydomain.com and other is subdomain.mydomain.com
Problem is that whenever I type the VPS IP in the browser, it goes to the subdomain. Is there a way to default this to the main domain?
I've created a folder called sites-enabled which contains both configuration files, they look something like this.
example.net.conf:
<VirtualHost *:80>
ServerName example.net
ServerAlias www.example.net
DocumentRoot /var/www/example.net
<Directory /var/www/example.net>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
<FilesMatch \.php$>
SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost"
</FilesMatch>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
admin.example.net.conf:
<VirtualHost *:80>
ServerName admin.example.net
DocumentRoot /var/www/admin.example.net
DirectoryIndex index.html
ErrorLog ${APACHE_LOG_DIR}/admin.example.net.log
CustomLog ${APACHE_LOG_DIR}/admin.example.net.log combined
</VirtualHost>
How can I set the first one to be the default?
place the below code in the 000-default.conf file
<VirtualHost *:80>
DocumentRoot /var/www/example.net
<Directory /var/www/example.net>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
<FilesMatch \.php$>
SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost"
</FilesMatch>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

deploy 2 flask projects using apache on Ubuntu (not duplicated)

please don't close the question as duplicated as it is a different issue.
I have an ubuntu server on Azure and I deployed a flask project on it and it is working fine, I wanted to deploy another project but it doesn't work, here is my sites.conf, please review it and tell me where is the issue.
<VirtualHost *:80>
ServerName server
ServerAdmin admin#email.com
ServerAlias project1.net
DocumentRoot /var/www/html/project1/
WSGIScriptAlias / /var/www/html/project1/project1.wsgi
WSGIPassAuthorization on
<Directory /var/www/html/project1/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/html/project1/static
<Directory /var/www/html/project1/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName server
ServerAdmin admin#email.com
ServerAlias project2.net
DocumentRoot /var/www/html/project2/
WSGIScriptAlias / /var/www/html/project2/project2.wsgi
WSGIPassAuthorization on
<Directory /var/www/html/project2/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/html/project2/static
<Directory /var/www/html/project2/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Apache virtualhost servername by ip + documentroot

I am trying to get this virtualhost working on apache + ubuntu. I want it to work without a real domainname but by ip and the path. It is now not getting activated. Is it possible to use the serverName like this or are only domain names valid?
<VirtualHost *:80>
serverName 37.35.66.98/just-do-it/
DocumentRoot /var/www/html/just-do-it/web
<Directory /var/www/html/just-do-it/web>
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Remove path portion from server name, then this should work
<VirtualHost *:80>
serverName 37.35.66.98
DocumentRoot /var/www/html/just-do-it/web
<Directory /var/www/html/just-do-it/web>
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
do not forget to add your server name in /etc/hosts file

virtual host not working in ubuntu 16.04

I'm working on an Ubuntu 16.04 server with Apache and I'm trying to setup 2 virtual host in the local server(192.168.50.200) . The problem is I don't know how to setup the .conf files correctly. i have created two configuration file in the site_available folder, enabled both configuration file using a2ensite command. And the below IP and URL included in the etc/host file
192.168.50.200 test.site1.com
192.168.50.200 test.site2.com
site1.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName test.site1.com/
DocumentRoot /var/www/site1.com
<Directory /var/www>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
site2.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName test.site2.com
DocumentRoot /var/www/site2.com
<Directory /var/www>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
these configuration links are available in the site_enabled folder.
After these configuration i restrated the apache server and also try to reboot the server but no luck.