Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automate Nginx Deployment #29

Open
dongbohu opened this issue Mar 27, 2019 · 2 comments
Open

Automate Nginx Deployment #29

dongbohu opened this issue Mar 27, 2019 · 2 comments

Comments

@dongbohu
Copy link
Contributor

This Django app is called by Nginx, which behaves as a reverse proxy to client requests. Here is the nginx configuration file:

# HTTP configuration 
# Default HTTP server: always redirect to HTTPS
server {
    listen 80 default_server;
    server_name _;
    return 301 https://$host$request_uri;
}

# HTTPS server
server {
    listen 443;
    server_name search-api.het.io;

    if ( $http_host !~* ^(search-api\.het\.io)$ ) {
        return 444;
    }

    ssl on;
    ssl_certificate /etc/letsencrypt/live/search-api.het.io/fullchain.pem;   # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/search-api.het.io/privkey.pem; # managed by Certbot

    charset utf-8;

    # max upload size (adjust to taste)
    client_max_body_size 10M;

    location / {
        return 301 $scheme://$host/v1;
    }

   location /static {
       alias /home/ubuntu/hetmech-backend/dj_hetmech/static;
    }

    location /v1 {
        proxy_pass http://127.0.0.1:8001/v1;
        proxy_set_header X-Forwarded-Host $server_name;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
    }

}

The directory /home/ubuntu/hetmech-backend/dj_hetmech/static (which holds static files for API view) should be populated by the following management command:

python manage.py collectstatic

Gunicorn is started at boot time by supervisord, with the following configuration:

command=/home/ubuntu/miniconda3/envs/hetmech-backend/bin/gunicorn dj_hetmech.wsgi:application --bind 127.0.0.1:8001 --error-logfile /tmp/hetmech-g
unicorn.log -w 3
directory=/home/ubuntu/hetmech-backend/
user=nobody
group=nobody
autostart=true
autorestart=true
priority=991
stopsignal=KILL
@dhimmel
Copy link
Collaborator

dhimmel commented Mar 27, 2019

This is helpful to jot down. Hopefully, in the medium term, we can design a solution that produces the server instance in an entirely scripted way. One solution that comes to mind is for this repository to define a Docker image with its environment. This image could be built / deployed by CI as necessary. @dongbohu interested to hear what you think is the best solution?

@dongbohu
Copy link
Contributor Author

dongbohu commented Mar 28, 2019

For now I can write a shell script to keep track of all deployment steps. Then if we (or users of this repo) need to deploy the backend, all they need to do is run this script on either docker container or cloud instances such as AWS EC2 or Google Cloud etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants