Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SHELL

NGINX setup for react plus django (rest framework) in same server

server_tokens               off;
access_log                  /var/log/nginx/mysite.access.log;
error_log                   /var/log/nginx/mysite.error.log;

# This configuration will be changed to redirect to HTTPS later
server {
  server_name               .example.com;
  listen                    80;
  location / {
        root   /var/www/html;  # location for React build files
        index  index.html index.htm;	# entry point for NGINX
		try_files $uri $uri/ /index.html;
  }

  location /akn {
        try_files $uri @proxy_api;	# call to pass proxy
  }
  location /admin {
    	try_files $uri @proxy_api;  # to use the default django admin
  }

  location @proxy_api {
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-Url-Scheme $scheme;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass   http://localhost:8000;
   }

  location /staticfiles {
	autoindex on;
	alias /var/www/akn/static/;
  }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #NGINX #setup #react #django #server
ADD COMMENT
Topic
Name
6+8 =