Etiket arşivi: ubuntu

Apache ssl virtualhost

Edit default-ssl configuration file;

<IfModule mod_ssl.c>

<VirtualHost _default_:443>
 ServerName blabla1.blabla.com:443
 ServerAdmin webmaster@localhost
 DocumentRoot /directory
 <Directory />
 Options FollowSymLinks
 AllowOverride None
 </Directory>
 <Directory /directory>
 Options FollowSymLinks MultiViews
 AllowOverride All
 Order allow,deny
 allow from all
 </Directory>

 ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
 <Directory "/usr/lib/cgi-bin">
 AllowOverride None
 Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
 Order allow,deny
 Allow from all
 </Directory>

 ErrorLog /var/log/apache2/error.log

 LogLevel warn

 CustomLog /var/log/apache2/ssl_access.log combined

 Alias /doc/ "/usr/share/doc/"
 <Directory "/usr/share/doc/">
 Options Indexes MultiViews FollowSymLinks
 AllowOverride None
 Order deny,allow
 Deny from all
 Allow from 127.0.0.0/255.0.0.0 ::1/128
 </Directory>

 SSLEngine on

 SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
 SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
 #SSLCertificateChainFile /etc/apache2/ssl.crt/server-ca.crt

 <FilesMatch "\.(cgi|shtml|phtml|php)$">
 SSLOptions +StdEnvVars
 </FilesMatch>
 <Directory /usr/lib/cgi-bin>
 SSLOptions +StdEnvVars
 </Directory>

 BrowserMatch "MSIE [2-6]" \
 nokeepalive ssl-unclean-shutdown \
 downgrade-1.0 force-response-1.0
 BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
</VirtualHost>

<VirtualHost _default_:443>
 ServerName blabla2.blabla.com:443
 ServerAdmin webmaster@localhost
 DocumentRoot /directory
 <Directory />
 Options FollowSymLinks
 AllowOverride None
 </Directory>
 <Directory /directory>
 Options FollowSymLinks MultiViews
 AllowOverride All
 Order allow,deny
 allow from all
 </Directory>

 ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
 <Directory "/usr/lib/cgi-bin">
 AllowOverride None
 Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
 Order allow,deny
 Allow from all
 </Directory>

 ErrorLog /var/log/apache2/error.log
 LogLevel warn

 CustomLog /var/log/apache2/ssl_access.log combined
 Alias /doc/ "/usr/share/doc/"
 <Directory "/usr/share/doc/">
 Options Indexes MultiViews FollowSymLinks
 AllowOverride None
 Order deny,allow
 Deny from all
 Allow from 127.0.0.0/255.0.0.0 ::1/128
 </Directory>
 SSLEngine on
 SSLCertificateFile /directoryCert
 SSLCertificateKeyFile /directoryCertKeyFile


 <FilesMatch "\.(cgi|shtml|phtml|php)$">
 SSLOptions +StdEnvVars
 </FilesMatch>
 <Directory /usr/lib/cgi-bin>
 SSLOptions +StdEnvVars
 </Directory>

 BrowserMatch "MSIE [2-6]" \
 nokeepalive ssl-unclean-shutdown \
 downgrade-1.0 force-response-1.0
 BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown

</VirtualHost>

 

Belirli bir site hariç tüm istekleri 443’e yönlendirme

 ServerName blabla.com
 ServerAlias www.blabla.com
 RewriteEngine on

 RewriteCond %{HTTP_HOST} ^(www\.)?buharic.com [NC]
 RewriteRule ^ - [L]
 RewriteRule ^/?(.*) https://%{HTTP_HOST}/$1

Yukarıdaki kural ile apache web sunucusuna gelen buharic.com haricinde gelen tüm istekler 443 portuna (https) yönlendirelecektir. Bu kural ile buharic.com isteği gelirse alttaki kurallar çalıştırılmayacak bu sayede yönlendirme yapılmayacaktır.

Ayrıca http://htaccess.madewithlove.be htaccess tester web sitesinden kurallarınızı test edebilirsiniz.

Apache2 redirect subdomains http to https

Edit /etc/apache2/sites-available/000-default as;

ServerAdmin admin@domain.com
ServerName domain.com
ServerAlias www.domain.com
RewriteEngine on
ReWriteCond %{SERVER_PORT} !^443$
RewriteRule ^/?(.*) https://%{HTTP_HOST}/$1 [NC,R,L]

Source: https://www.digitalocean.com/community/questions/ubuntu-14-04-apache2-how-to-confi-https-and-subdomain

Ubuntu 16.04 Postgresql Installation and Restore SQL Dump

sudo apt-get install postgresql
sudo -u postgres -i
psql CREATE DATABASE dbname;
psql dbname < directory/data_backup.sql

\l --> list all database
\c dbname;  --> select database to use
\d+ --> list properties of the database
\d tablename describe table;

SELECT * FROM tablename WHERE column1 = 'asd' AND column2 = 'bcd';

:q --> quit from query