Date
Nov. 21st, 2024
 
2024年 10月 21日

Post: Nginx Cheatsheet

Nginx Cheatsheet

Published 08:08 Aug 02, 2020.

Created by @ezra. Categorized in #Programming, and tagged as #Cheatsheet.

Source format: Markdown

Table of Content
  • tail -f /var/log/nginx/error.log -- for viewing error logs in nginx

Django setup cheat sheet

nginx

user www-data;
worker_processes auto;

pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
  worker_connections 768;
  # multi_accept on;
}

http {

  upstream test_server {
    server unix:/var/www/html/demirantay/run/gunicorn.sock fail_timeout=10s;
  }

  server {
    include  /etc/nginx/mime.types;
    server_name  www.getdemir.com getdemir.com;

    client_max_body_size 4G;

    # access_log /var/www/test/logs/nginx-access.log;
    # error_log /var/www/test/logs/nginx-error.log warn;

    location /static/ {
      autoindex on;
      alias /var/www/html/demirantay/staticfiles/;
    }

    location /media/ {
      autoindex on;
      alias /var/www/html/demirantay/media/;
    }

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;

        if (!-f $request_filename) {
          proxy_pass http://test_server;
          break;
        }

    }

  }

}

django static files:

# Static

STATIC_URL = '/static/'
STATICFILES_DIRS = (os.path.join(BASE_DIR, "static"),)
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")

MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
Pinned Message
HOTODOGO
The Founder and CEO of Infeca Technology.
Developer, Designer, Blogger.
Big fan of Apple, Love of colour.
Feel free to contact me.
反曲点科技创始人和首席执行官。
开发、设计与写作皆为所长。
热爱苹果、钟情色彩。
随时恭候 垂询