Skip to content

Commit

Permalink
New nginx config
Browse files Browse the repository at this point in the history
  • Loading branch information
stevebrownlee committed May 25, 2023
1 parent 4f2ce6e commit 385f9df
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 19 deletions.
19 changes: 1 addition & 18 deletions config/nginx.api.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
server {
server_name learningapi.nss.team;
listen 80;
access_log /var/log/nginx/api.log;

location / {
Expand All @@ -14,22 +15,4 @@ server {
autoindex off;
root /var/www/learning.nss.team/;
}

listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/learningapi.nss.team/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/learningapi.nss.team/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}


server {
if ($host = learningapi.nss.team) {
return 301 https://$host$request_uri;
} # managed by Certbot


listen 80;
server_name learningapi.nss.team;
return 404; # managed by Certbot
}
34 changes: 34 additions & 0 deletions config/nginx.client.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
server {
server_name learning.nss.team;

root /home/chortlehoort/actions-runner/_work/learn-ops-client/learn-ops-client/build;

index index.html index.htm;

location / {
try_files $uri $uri/ /index.html$is_args$args;
}

access_log /var/log/nginx/client.log;


listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/learning.nss.team/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/learning.nss.team/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server {
if ($host = learning.nss.team) {
return 301 https://$host$request_uri;
} # managed by Certbot


server_name learning.nss.team;
listen 80;
return 404; # managed by Certbot


}
30 changes: 29 additions & 1 deletion setup_ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ python3 manage.py loaddata socialaccount
python3 manage.py loaddata complete_backup
python3 manage.py loaddata superuser
rm $API_HOME/LearningAPI/fixtures/superuser.json
python3 manage.py collectstatic
EOF


Expand Down Expand Up @@ -295,7 +296,7 @@ Environment="LEARN_OPS_ALLOWED_HOSTS=${LEARN_OPS_ALLOWED_HOSTS}"
User=${LEARN_OPS_USER}
Group=www-data
WorkingDirectory=$API_HOME
ExecStart=/var/www/learningapi/venv/bin/gunicorn -w 3 --bind 127.0.0.1:8000 --log-file /var/www/learningapi/learning.log --access-logfile /var/www/learningapi/learning-access.log LearningPlatform.wsgi
ExecStart=/var/www/learningapi/venv/bin/gunicorn -w 3 --bind 127.0.0.1:8000 --log-file /var/www/learningapi/logs/learning.log --access-logfile /var/www/learningapi/logs/learning-access.log LearningPlatform.wsgi
PrivateTmp=true
[Install]
Expand All @@ -312,3 +313,30 @@ if [ "${SYSTEMD_PID}" == "" ]; then
else
sudo service learning start >> /dev/null
fi


#####
# Create nginx reverse proxy for API
#####

echo 'server {
listen 80;
server_name staging.nss.team;
location / {
proxy_pass http://localhost:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
}
location /static/ {
autoindex off;
root /var/www/learning.nss.team/;
}
}
' > /etc/nginx/sites-available/api

ln -s /etc/nginx/sites-available/api /etc/nginx/sites-enabled/api
sudo systemctl restart nginx

0 comments on commit 385f9df

Please sign in to comment.