Raportti 4

I decided to create a vps in amsterdam and use cloudflare’s dns service

first i created the droplet in digital ocean

Screenshot from 2018-09-13 16-03-40Screenshot from 2018-09-13 16-04-23Screenshot from 2018-09-13 16-05-43

next step i did was to configure the server for installing nginx

so first

Screenshot from 2018-09-13 16-14-12

first i sshed to the server

then i added my self to sudo and disabled login to ssh by root

and allowed ports 22,80 and 443 in firewall

next i installed nginx

Screenshot from 2018-09-13 16-27-25

then i changed dns settings in cloudflare to match the serverScreenshot from 2018-09-13 16-07-58

next step is to install ssl to the webserver using letsencrypt

after installing ssl with cloudflare you might have this problemScreenshot from 2018-09-13 16-44-06

to solve it go to cloudflare.com and login to your account and click crypto

Screenshot from 2018-09-13 16-45-54

change where it says flexible to full

now your site works

Screenshot from 2018-09-13 16-46-55

now to install django with nginx

Screenshot from 2018-09-13 16-48-54Screenshot from 2018-09-13 16-49-07Screenshot from 2018-09-13 16-50-13

now i switched to the postgres user

next i open the postresql shell

Screenshot from 2018-09-13 16-52-01

CREATE USER myprojectuser WITH PASSWORD ’password’;

creates a user called myprojectuser with the password of ’password’

GRANT ALL PRIVILEGES ON DATABASE myproject TO myprojectuser;

grants permission to database ’myproject’ to ’myprojectuser’

\q

exit

to return to your user shell

 

next step is to install gunicorn service

sudo nano /etc/systemd/system/gunicorn.service

[Unit]
Description=gunicorn daemon
After=network.target

[Service]
User=user
Group=nginx
WorkingDirectory=/home/user/myproject
ExecStart=/usr/local/bin/startserver

[Install]
WantedBy=multi-user.target

start server contents

#!/bin/bash

PYTHONPATH=`pwd`/ /home/omar/myproject/myprojectenv/bin/gunicorn –workers 3 –bind unix:/home/omar/myproject/myproject.sock myproject.wsgi:application

this is the gunicorn socket required for nginx

location / {
include proxy_params;
proxy_pass http://unix:/home/omar/myproject/myproject.sock;
}

is the only change to nginx configuration

and django settings

Screenshot from 2018-09-13 17-46-55Screenshot from 2018-09-13 17-43-22

default site of django

https://omarbenchbana.com/hello/Screenshot from 2018-09-13 18-24-50.png

Mainokset

Vastaa

Täytä tietosi alle tai klikkaa kuvaketta kirjautuaksesi sisään:

WordPress.com-logo

Olet kommentoimassa WordPress.com -tilin nimissä. Log Out /  Muuta )

Google+ photo

Olet kommentoimassa Google+ -tilin nimissä. Log Out /  Muuta )

Twitter-kuva

Olet kommentoimassa Twitter -tilin nimissä. Log Out /  Muuta )

Facebook-kuva

Olet kommentoimassa Facebook -tilin nimissä. Log Out /  Muuta )

Muodostetaan yhteyttä palveluun %s