Skip to content

Instantly share code, notes, and snippets.

@RenanMatias
Last active April 16, 2022 00:18
Show Gist options
  • Save RenanMatias/d5d24e11e008dba99b3e3f56f92add14 to your computer and use it in GitHub Desktop.
Save RenanMatias/d5d24e11e008dba99b3e3f56f92add14 to your computer and use it in GitHub Desktop.
Configuração do NGINX HTTP

NGINX HTTP

Reference

https://www.nginx.com/blog/using-free-ssltls-certificates-from-lets-encrypt-with-nginx/

Replaces

  • ____REPLACE_ME_WITH_YOUR_OWN_DOMAIN____ = Replace with your domain
  • __PROJECT_FOLDER__ = Replace with the path to the folder for the project
  • __STATIC_FOLDER_PATH__ = Replace with the path to the folder for static files
  • __MEDIA_FOLDER_PATH__ = Replace with the path to the folder for media files
  • __SOCKET_NAME__ = Replace with your unix socket name

HTTP

server {
  listen 80;
  listen [::]:80;
  server_name ____REPLACE_ME_WITH_YOUR_OWN_DOMAIN____;
  
  client_max_body_size 10M;

  # Add index.php to the list if you are using PHP
  index index.html index.htm index.nginx-debian.html index.php;
  
  # ATTENTION: __STATIC_FOLDER_PATH__
  location /static {
    autoindex on;
    alias __STATIC_FOLDER_PATH__;
  }

  # ATTENTION: __MEDIA_FOLDER_PATH__ 
  location /media {
    autoindex on;
    alias __MEDIA_FOLDER_PATH__;
  }

  # ATTENTION: __SOCKET_NAME__
  location / {
    proxy_pass http://unix:/run/__SOCKET_NAME__;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
  }

  # deny access to .htaccess files, if Apache's document root
  # concurs with nginx's one
  #
  location ~ /\.ht {
    deny all;
  }

  location ~ /\. {
    access_log off;
    log_not_found off;
    deny all;
  }

  gzip on;
  gzip_disable "msie6";

  gzip_comp_level 6;
  gzip_min_length 1100;
  gzip_buffers 4 32k;
  gzip_proxied any;
  gzip_types
    text/plain
    text/css
    text/js
    text/xml
    text/javascript
    application/javascript
    application/x-javascript
    application/json
    application/xml
    application/rss+xml
    image/svg+xml;

  access_log off;
  #access_log  /var/log/nginx/____REPLACE_ME_WITH_YOUR_OWN_DOMAIN____-access.log;
  error_log   /var/log/nginx/____REPLACE_ME_WITH_YOUR_OWN_DOMAIN____-error.log;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment