Skip to content

Commit

Permalink
serving static from nginx while production
Browse files Browse the repository at this point in the history
  • Loading branch information
khaledboka committed Jun 14, 2020
1 parent 71d56f2 commit 690c725
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 49 deletions.
21 changes: 11 additions & 10 deletions docker-compose.yml
@@ -1,4 +1,4 @@
version: '3'
version: "3"
services:
postgis:
image: kartoza/postgis:11.5-2.5
Expand All @@ -11,8 +11,7 @@ services:
- POSTGRES_USER=docker
- POSTGRES_PASS=docker
- ALLOW_IP_RANGE=0.0.0.0/0
# Add extensions you need to be enabled by default in the DB. Default are the five specified below
- POSTGRES_MULTIPLE_EXTENSIONS=postgis,hstore,postgis_topology,postgis_raster,pgrouting
- POSTGRES_MULTIPLE_EXTENSIONS=postgis
expose:
- "5432"
restart: on-failure
Expand Down Expand Up @@ -109,20 +108,22 @@ services:
- "80"
volumes:
- ./scripts/nginx/nginx.conf:/etc/nginx/nginx.conf
- ./static/:/cartoview/static/
- ./uploaded/:/cartoview/uploaded/
networks:
-cartoview-external:
ipv4_address: 10.5.0.4
-cartoview-internal:
ports:
- "80:80"
networks:
-cartoview-external:
driver: bridge
ipam:
config:
- subnet: 10.5.0.0/16
-cartoview-internal:
internal: true
-cartoview-external:
driver: bridge
ipam:
config:
- subnet: 10.5.0.0/16
-cartoview-internal:
internal: true
volumes:
geoserver-dir:
postgis-data:
3 changes: 2 additions & 1 deletion env/django.env
Expand Up @@ -8,4 +8,5 @@ DOCKER=True
ALLOWED_HOSTS=['*']
PROJECT_NAME=cartoview
DEFAULT_BACKEND_DATASTORE=datastore
CARTOVIEW_STAND_ALONE=True
CARTOVIEW_STAND_ALONE=True
DEBUG=False
70 changes: 32 additions & 38 deletions scripts/nginx/nginx.conf
@@ -1,63 +1,57 @@
user nginx;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
user nginx;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
worker_connections 1024;
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;
access_log /var/log/nginx/access.log main;

sendfile on;
sendfile on;
#tcp_nopush on;

keepalive_timeout 65;
keepalive_timeout 65;

gzip on;
gzip on;
gzip_min_length 500;
gzip_proxied expired no-cache no-store private auth;
gzip_types *;
gzip_comp_level 9;
server{
gzip_proxied expired no-cache no-store private auth;
gzip_types *;
gzip_comp_level 9;
server {
listen 80;
server_name localhost;
index index.html index.htm;
root /usr/share/nginx/html;
location /{
root /usr/share/nginx/html;
location / {
client_max_body_size 1024M;
client_body_buffer_size 1024K;
proxy_read_timeout 100000;
proxy_set_header Host $host;
proxy_set_header Host $host;
proxy_pass http://cartoview:8000;
}
#location /geoserver/ {
# proxy_pass http://geoserver:8080/geoserver/;
#}
location /geoserver {

# Using a variable is a trick to let Nginx start even if upstream host is not up yet
# (see https://sandro-keil.de/blog/2017/07/24/let-nginx-start-if-upstream-host-is-unavailable-or-down/)
proxy_pass http://geoserver:8080;
#set $upstream geoserver:8080;

proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

proxy_pass http://geoserver:8080;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /static {
alias /cartoview/static/;
}
location /uploaded {
alias /cartoview/uploaded/;
}
}
#include /etc/nginx/conf.d/*.conf;
}

0 comments on commit 690c725

Please sign in to comment.