Apache web server multiple project folder hosting issue - apache

I have configured /etc/apache2/sites-enabled/000-default.conf as follows .
ServerName 0.0.0.0
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
WSGIDaemonProcess python-app threads=15 maximum-requests=10000
WSGIScriptAlias / /var/www/html/myapp/myapp.wsgi
WSGIProcessGroup python-app
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/html/myapp>
Order deny,allow
Allow from all
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/www/html/test"
<Directory "/var/www/html/test">
AllowOverride All
</Directory>
</VirtualHost>
Now my project folder structure is like :
I am able to access myapp (python flask project) . But not my test project html files. Looks like the myapp.wsgi (via flask app) is managing all the urls . url like test\index.html (to access test project) is not configured in flask app and hence getting error.

It worked after updating WSGIScriptAlias /api /var/www/html/myapp/myapp.wsgi. Need to call apis with /api in-front
Initially it was WSGIScriptAlias / /var/www/html/myapp/myapp.wsgi overriding all url mappings.

Related

Apache Dynamic VirtualHost routing not working

I have a Codeigniter project that i want to access on main domain e.g domain.com and on multiple dynamic subdomains. The project files are at /var/www/ Directory. Each of the sub-directories are being accessed via "SubdirectoryName.domain.com".
I am using virtual hosts configuration and my main domain is working fine with all its routing but on subdomains, main page is working but routing and htaccess is not working. If i add/index.php in url it works but due to htaccess not working im not able to remove it from url.
I have tried this virtualhost configuration but it doesn't seem to work
This is my virtualhost conf file code
<VirtualHost *:80>
ServerName domain.co.uk
ServerAlias www.domain.co.uk
ServerAdmin webmaster#testing.com
DocumentRoot /var/www/domain.co.uk/public_html/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/domain.co.uk/public_html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName domain.co.uk
ServerAlias *.domain.co.uk
ServerAdmin webmaster#testing.com
VirtualDocumentRoot /var/www/%1
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

How can i run flask wsgi app with apache on port :5000

I am trying to deploy flask app like api on :5000 port(returning jsons).
What am i doing wrong?(it is not working).
My .conf file:
<VirtualHost *:5000>
ServerAdmin webmaster#localhost
WSGIDaemonProcess flaskapp threads=5
WSGIScriptAlias / /var/www/html/photochooser/app.wsgi
WSGIApplicationGroup %{GLOBAL}
<Directory flaskapp>
WSGIProcessGroup flaskapp
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Then im typing a2ensite ....conf, restarting apache
And ip:5000 returning "Page not found"
P.S. its working on :80, but i need this port for my react client side.
Found solution by myself:
Edited /etc/apache2/ports.conf:
Added ''' Listen 5000 '''
And then ip:5000 started working :)

Apache2 does not serve ServerAlias without www

This is my sites-available/FlaskApp.conf file
<VirtualHost *:80>
ServerName www.mywebsite.design
ServerAlias mywebsite.design
ServerAdmin myemail#gmail.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>
www.mywebsite.design works when i open on the browser correctly. However when i go to mywebsite.design the Ubuntu Default "It Works" page shows up.
I followed this tutorial Hosting a FlaskApp
When i tried IPAddress as the Servername like this -
ServerName 139.55.55.55
for some reason the opening the IP address on the browser opens correctly but both www.mywebsite.design or mywebsite.design don't shows the same Ubuntu Default Page
I had mywebsite.design on /etc/hosts like this -
127.0.1.1 mywebsite.design mywebsite
. probably because i named the project that way at some point!
Removed it and just put my name there and it worked!

Change Laravel base URL from localhost to localhost/laravel5

I'm trying to change Laravel base URL to localhost/laravel5, I tried to change APP_URL variable in .env file, I did the same changes to this line in config/app.php file:
'url' => env('APP_URL', 'http://localhost/laravel5')
And here my /etc/apache2/sites-available/laravel.conf file:
<VirtualHost *:80>
ServerName localhost/laravel5
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/laravel5/public
<Directory /var/www/html/laravel5>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I also tried to restart apache2 service, but nothing changes
Make your virtual server like this in apache
<VirtualHost *:80>
ServerName laravel5.app
DocumentRoot /var/www/html/laravel5/public
<Directory /var/www/html/laravel5/public>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
and run
sudo a2ensite laravel5.app
service apache2 reload
Finally, make sure to edit your /etc/hosts file and add an entry for laravel5.app:
# other entries...
# your entry...
127.0.0.1 laravel5.app
And then you can access your app at http://laravel5.app
I recommend You to use something like Homestead or Valet for developing Check the docs here

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>