NGINX-konfigurasjon

Slik ser nginx-konfigurasjonen ut.

  1##
  2# You should look at the following URL's in order to grasp a solid understanding
  3# of Nginx configuration files in order to fully unleash the power of Nginx.
  4# https://www.nginx.com/resources/wiki/start/
  5# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
  6# https://wiki.debian.org/Nginx/DirectoryStructure
  7#
  8# In most cases, administrators will remove this file from sites-enabled/ and
  9# leave it as reference inside of sites-available where it will continue to be
 10# updated by the nginx packaging team.
 11#
 12# This file will automatically load configuration files provided by other
 13# applications, such as Drupal or Wordpress. These applications will be made
 14# available underneath a path with that package name, such as /drupal8.
 15#
 16# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
 17##
 18
 19upstream socketio_nodes {
 20    ip_hash;
 21
 22    server 127.0.0.1:8000;
 23    #server 127.0.0.1:5001;
 24    #server 127.0.0.1:5002;
 25    # to scale the app, just add more nodes here!
 26}
 27
 28# Default server configuration
 29server {
 30    listen 80;
 31    listen [::]:80;
 32    server_name gruppe1.tech www.gruppe1.tech;
 33
 34    return 301 https://$host$request_uri;
 35}
 36
 37server {
 38    listen 443 ssl http2;
 39    listen [::]:443 ssl http2;
 40    server_name docs.gruppe1.tech;
 41
 42
 43    ssl_certificate /etc/letsencrypt/live/gruppe1.tech/fullchain.pem;
 44    ssl_certificate_key /etc/letsencrypt/live/gruppe1.tech/privkey.pem;
 45
 46    root /srv/docs/_build/html;
 47
 48    index index.html;
 49
 50    location / {
 51        try_files $uri $uri/ =404;
 52    }
 53}
 54
 55server {
 56	listen 443 ssl http2;
 57    listen [::]:443 ssl http2;
 58
 59	root /var/www/html;
 60
 61	index index.html; 
 62
 63    server_name gruppe1.tech www.gruppe1.tech;
 64
 65    ssl_certificate /etc/letsencrypt/live/gruppe1.tech/fullchain.pem;
 66    ssl_certificate_key /etc/letsencrypt/live/gruppe1.tech/privkey.pem;
 67
 68    #reverse proxy flask
 69    location / {
 70        proxy_pass http://127.0.0.1:8000/;
 71        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 72        proxy_set_header X-Forwarded-Proto $scheme;
 73        proxy_set_header Host $host;
 74        proxy_set_header X-Real-IP $remote_addr;
 75
 76        error_page 502 = /fallback;
 77	}
 78	
 79    
 80    location /socket.io {
 81        include proxy_params;
 82        proxy_http_version 1.1;
 83        proxy_set_header Upgrade $http_upgrade;
 84        proxy_set_header Connection "Upgrade";
 85        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 86        proxy_pass http://socketio_nodes/socket.io;
 87        proxy_buffering off;
 88    }
 89
 90
 91	location /fallback {
 92        internal;
 93		try_files /index.html =502;
 94	}
 95}
 96
 97
 98# Virtual Host configuration for example.com
 99#
100# You can move that to a different file under sites-available/ and symlink that
101# to sites-enabled/ to enable it.
102#
103#server {
104#	listen 80;
105#	listen [::]:80;
106#
107#	server_name example.com;
108#
109#	root /var/www/example.com;
110#	index index.html;
111#
112#	location / {
113#		try_files $uri $uri/ =404;
114#	}
115#}

Forklaring:

upstream
  • Ruter websocketen korrekt i henhold til gunicorn.

server:
  • Definerer en ny virtuell server.

location /:
  • Håndterer forespørsler til rot-URL-en.