DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Deploy Your Static or Dynamic Websites Using Git in Public Cloud

Deploy Your Static or Dynamic Websites Using Git in Public Cloud

Do you want to save some pennies or just for a quick demo? Well, that doesn't necessarily mean that you need to rent a VM.

Denny Zhang user avatar by
Denny Zhang
·
Oct. 18, 16 · Tutorial
Like (5)
Save
Tweet
Share
4.66K Views

Join the DZone community and get the full member experience.

Join For Free

so, you don’t want to start vms in public cloud

if you want to save some pennies or just for a quick demo, you don’t necessarily need to rent a vm. you can run websites directly in your laptop, linux, or mac (pity for windows users), then export your laptop to the internet .

allow git clone by ssh key and run git pull every 10 minutes

configure github/bitbucket your ssh key.

i assume you’re familiar with git clone by ssh. probably like lots of developers, you will use your own private key. i highly disagree with that. too dangerous! your ssh private key can unlock lots of precious treasures, far more than this git repo. right?

git deploy key

how to improve? create a read-only git deploy key in github/bitbucket repo setting. to do that, we need to create a new ssh key pair so that it’s new and isolated. and git deploy key has a nice limitation: we can’t use the same deploy key for multiple repos . it adds extra security.

for simplicity or reasonable security compromise, some people may still use their private key. i admit, it makes sense to some extent. then, protect your ssh key with a passphrase . it’s easy and simple.

for simplicity, here, we use root to checkout the code and set up the website. to improve the security, try with an ordinary os user.

# update ssh key to below
vim /root/git_deploy_key

# ssh private key can't be widely open
chmod 400 /root/git_deploy_key

specify the ssh key for the git clone:

vim /root/.ssh/config

host github.com
     hostname github.com
     stricthostkeychecking no
     user git
     identityfile /root/git_deploy_key

run the g it clone to get the repo:

# run with correct parameters.
cd /var/www/
git clone git@github.com:xxx/denny_www.git

create a crontab for a periodical g git pull . now, there is no need for manual login and update anymore.

crontab -e

# change file path
*/10 * * * * cd /var/www/denny_www; git pull

for static websites, create apache vhost

for static websites of plain html, we don’t need to run  with our own server. it can be done with github pages . see more discussion here .

well, github pages only solves 80% of the problem. if you’re in china, the accessibility of github is not guaranteed. you may want to use your own domain instead of xxx.github.io. use apache2 or nginx to serve the requests.

apache vhost example (nginx is pretty similar):

# install apache
apt-get install -y apache2

# define vhost
vim /etc/apache2/sites-enabled/my-static.conf

<virtualhost *:80>
    serveradmin webmaster@dummy.test.com
    documentroot /var/www/denny_www
    <directory '/var/www/denny_www'>
        options all
        allowoverride all
        require all granted
    </directory>
    errorlog /var/log/apache2/my-error.log
    customlog /var/log/apache2/my.log common
</virtualhost>

# reload apache
service apache2 reload

for dynamic websites, use apache for http reverse proxy

let’s say your dynamic website listens on port 8082 and you want to open by my test .

configure the dns setting properly or be sure that /etc/hosts is properly changed. then, enable apache modules for:

a2enmod proxy
a2enmod proxy_http

# restart apache to load modules
service apache2 restart

vim /etc/apache2/sites-enabled/dynamic.conf:

<virtualhost *:80>
servername www.mytest.com
serveralias mytest.com
serveradmin webmaster@smallco.example.com
errorlog /var/log/apache2/dynamic_error_log
transferlog /var/log/apache2/dynamic_access_log
documentroot /var/www
proxypass / http://127.0.0.1:8082/
proxypassreverse / http://127.0.0.1:8082/
</virtualhost>

if necessary, configure the firewall to allow the traffic:

ufw allow 80/tcp

# some uri might has port number attached
ufw allow 8082/tcp
curl -i http://www.mytest.com

add password protection to your existing websites

sometimes, you may only want certain people to visit your websites. with apache htpasswd , we can create a username-password pair easily. people will need to input the credential first in their web browser before the actual pages load.

create a user credential:

apt-get install -y apache2-utils

# create password file for a new user
/etc/apache2/.htpasswd $username

update the vhost setting to enforce the authentication from...

<virtualhost *:80>
    serveradmin webmaster@localhost
    documentroot /var/www/html
    errorlog ${apache_log_dir}/error.log
    customlog ${apache_log_dir}/access.log combined

    <directory "/var/www/html">
    </directory>
</virtualhost>

...to:

<virtualhost *:80>
    serveradmin webmaster@localhost
    documentroot /var/www/html
    errorlog ${apache_log_dir}/error.log
    customlog ${apache_log_dir}/access.log combined

    <directory "/var/www/html">
        authtype basic
        authname "restricted content"
        authuserfile /etc/apache2/.htpasswd
        require valid-user
    </directory>
</virtualhost>

verify the setting and open http://$domain_name:$port in your web browser.

enforce username and password for apache

monitor your websites with free saas monitoring

check your url every five minutes. if the url doesn’t return http 200 ok or tcp ports down, then we get alerts.

from my experience, i highly recommend uptimerobot . it’s a very reliable and light-weight saas monitoring service and it’s totally free. you can even integrate the alert notification with slack via a slack email robot.

more reading: effectively technical writing in github

Git Cloud

Published at DZone with permission of Denny Zhang, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Silver Bullet or False Panacea? 3 Questions for Data Contracts
  • OpenID Connect Flows
  • The Real Democratization of AI, and Why It Has to Be Closely Monitored
  • Multi-Cloud Database Deep Dive

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: