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>
Related
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>
How to defend my apache2 server from anti DNS pinning and anti dns rebinding?
I work in company where is inform safety is important, but they only can test in one platform and tell me where is problem(
I am front-end and do not know how to defend my server ( Madly I hope that you will help with advice and show me the right path! Thank you very much in advance )
This is my
site.name.conf
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin webmaster#localhost
ServerName site.name
ServerAlias site.name
DocumentRoot /data/edu3/public
<Directory /data/edu3/>
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Include /etc/apache2/options-ssl-apache.conf
SSLCertificateFile /data/ssl/u1.crt
SSLCertificateKeyFile /data/ssl/u1.key
</VirtualHost>
<VirtualHost *:443>
ServerName catchall
<Location />
Order allow,deny
Deny from all
</Location>
</VirtualHost>
</IfModule>
<VirtualHost 10.224.32.10:80>
ServerAdmin webmaster#localhost
ServerName site.name
DocumentRoot /data/edu3/public
<Directory /data/edu3/>
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost _default_:*>
ServerName catchall
<Location />
Order allow,deny
Deny from all
</Location>
</VirtualHost>
<VirtualHost 10.224.32.10:80>
ServerName catchall
<Location />
Order allow,deny
Deny from all
</Location>
</VirtualHost>
The easiest way is to add this virtualhost separately, and make sure that the virtualhost for the main website is using the ServerName directive.
<VirtualHost _default_:80>
ServerAdmin webmaster#localhost
DocumentRoot "/path/to/defaultpagedirectory"
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log
</VirtualHost>
Basically what this does is that, it has a default page in the document root (you have to create it), it will serve that default page to the user if the Host header differs.
I want to serve up different 'look' and content for users on my flask site based on the virtualhost they use to reach the site without duplicating the entire code tree.
E.g. going to red.mysite.com would serve up red pages and 'red' content where the default is white.
I can do this today for the look using using a custom static tree in the Apache config to se the css and images but I want to have a custom /template tree too so I can change the page content in my templates to 'Red' versions.
Is there a way to set template dir from VirtualHost directives like with /static?
<VirtualHost *:80>
ServerName mysite.com
ServerAdmin admin#mywebsite.com
WSGIScriptAlias / /var/www/mysite.wsgi
<Directory /var/www/mysite/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/mysite/static
<Directory /var/www/mysite/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 red.mysite.com
ServerAdmin admin#mywebsite.com
WSGIScriptAlias / /var/www/mysite.wsgi
<Directory /var/www/mysite/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/mysite/red/static
<Directory /var/www/mysite/red/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Graham pointed me down the right path.
Here is how I did it:
changed conf to add in processgroup
<VirtualHost *:80>
ServerName mysite.com
ServerAdmin admin#mywebsite.com
WSGIDaemonProcess default
WSGIProcessGroup default
WSGIScriptAlias / /var/www/mysite.wsgi
<Directory /var/www/mysite/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/mysite/static
<Directory /var/www/mysite/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 red.mysite.com
ServerAdmin admin#mywebsite.com
WSGIDaemonProcess red
WSGIProcessGroup red
WSGIScriptAlias / /var/www/mysite.wsgi
<Directory /var/www/mysite/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/mysite/red/static
<Directory /var/www/mysite/red/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Modified Flask app creation as follows:
import mod_wsgi
instance = mod_wsgi.process_group
if instance == 'red':
app = Flask(__name__, template_folder='red/templates')
else:
app = Flask(__name__)
Now anyone coming in on the 'Red' URL sees templates in red/templates.
Bill
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
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..