Skip to content

Instantly share code, notes, and snippets.

@adamryan1983
Forked from iam-hussain/default HTTP
Created November 2, 2022 02:00
Show Gist options
  • Save adamryan1983/39d1f0f1201333db91e559339d4495c4 to your computer and use it in GitHub Desktop.
Save adamryan1983/39d1f0f1201333db91e559339d4495c4 to your computer and use it in GitHub Desktop.

Revisions

  1. @iam-hussain iam-hussain revised this gist Feb 28, 2022. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion support.sh
    Original file line number Diff line number Diff line change
    @@ -25,4 +25,8 @@ sudo ufw allow 'Nginx Full'


    # Port verification
    sudo lsof -i TCP:80
    sudo lsof -i TCP:80


    #for SSH
    # https://www.nginx.com/blog/using-free-ssltls-certificates-from-lets-encrypt-with-nginx/
  2. @iam-hussain iam-hussain revised this gist Feb 28, 2022. 1 changed file with 11 additions and 0 deletions.
    11 changes: 11 additions & 0 deletions support.sh
    Original file line number Diff line number Diff line change
    @@ -8,10 +8,21 @@ sudo nginx -s reload
    # Status
    sudo systemctl status nginx

    # start
    sudo systemctl start nginx

    # Restart
    sudo systemctl restart nginx

    # Stop
    sudo systemctl stop nginx

    # Nginx Security
    sudo ufw app list

    sudo ufw allow 'Nginx Full'



    # Port verification
    sudo lsof -i TCP:80
  3. @iam-hussain iam-hussain revised this gist Feb 28, 2022. 1 changed file with 17 additions and 0 deletions.
    17 changes: 17 additions & 0 deletions support.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@

    # Test Nginx config
    sudo nginx -t

    # If you got error then just delete the log.txt file then
    sudo nginx -s reload

    # Status
    sudo systemctl status nginx

    # Restart
    sudo systemctl restart nginx

    # Nginx Security
    sudo ufw app list

    sudo ufw allow 'Nginx Full'
  4. @iam-hussain iam-hussain revised this gist Nov 11, 2021. 2 changed files with 2 additions and 6 deletions.
    4 changes: 1 addition & 3 deletions Serve NextJS app with NGINX http → default HTTP
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,10 @@
    # Serve nextJS app from a port through NGINX reverse proxy (HTTP)
    # Path: /etc/nginx/sites-available/default
    # Default server configuration for HTTP

    server {
    server_name www.DOMAINNAME.com DOMAINNAME.com;

    index index.html index.htm;
    root /home/ubuntu/PROJECT_FOLDER; #Make sure your using the full path

    # Serve any static assets with NGINX
    location /_next/static {
    alias /home/ubuntu/PROJECT_FOLDER/.next/static;
    4 changes: 1 addition & 3 deletions Serve NextJS app with NGINX https → default HTTPS
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,10 @@
    # Serve nextJS app from a port through NGINX reverse proxy (HTTPS)
    # Path: /etc/nginx/sites-available/default
    # Default server configuration for HTTPS

    server {
    server_name www.DOMAINNAME.com DOMAINNAME.com;

    index index.html index.htm;
    root /home/ubuntu/PROJECT_FOLDER; #Make sure your using the full path

    # Serve any static assets with NGINX
    location /_next/static {
    alias /home/ubuntu/PROJECT_FOLDER/.next/static;
  5. @iam-hussain iam-hussain revised this gist Nov 2, 2021. 2 changed files with 0 additions and 0 deletions.
  6. @iam-hussain iam-hussain revised this gist Nov 2, 2021. 2 changed files with 0 additions and 0 deletions.
    File renamed without changes.
    File renamed without changes.
  7. @iam-hussain iam-hussain created this gist Nov 2, 2021.
    39 changes: 39 additions & 0 deletions http
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    # Path: /etc/nginx/sites-available/default
    # Default server configuration for HTTP

    server {
    server_name www.DOMAINNAME.com DOMAINNAME.com;

    index index.html index.htm;
    root /home/ubuntu/PROJECT_FOLDER; #Make sure your using the full path

    # Serve any static assets with NGINX
    location /_next/static {
    alias /home/ubuntu/PROJECT_FOLDER/.next/static;
    add_header Cache-Control "public, max-age=3600, immutable";
    }

    location / {
    try_files $uri.html $uri/index.html # only serve html files from this dir
    @public
    @nextjs;
    add_header Cache-Control "public, max-age=3600";
    }

    location @public {
    add_header Cache-Control "public, max-age=3600";
    }

    location @nextjs {
    # reverse proxy for next server
    proxy_pass http://localhost:8080; #Don't forget to update your port number
    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;
    }

    listen 80 default_server;
    listen [::]:80;
    }
    62 changes: 62 additions & 0 deletions https
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,62 @@
    # Path: /etc/nginx/sites-available/default
    # Default server configuration for HTTPS

    server {
    server_name www.DOMAINNAME.com DOMAINNAME.com;

    index index.html index.htm;
    root /home/ubuntu/PROJECT_FOLDER; #Make sure your using the full path

    # Serve any static assets with NGINX
    location /_next/static {
    alias /home/ubuntu/PROJECT_FOLDER/.next/static;
    add_header Cache-Control "public, max-age=3600, immutable";
    }

    location / {
    try_files $uri.html $uri/index.html # only serve html files from this dir
    @public
    @nextjs;
    add_header Cache-Control "public, max-age=3600";
    }

    location @public {
    add_header Cache-Control "public, max-age=3600";
    }

    location @nextjs {
    # reverse proxy for next server
    proxy_pass http://localhost:8080; #Don't forget to update your port number
    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;
    }

    listen [::]:443 ssl ipv6only=on;
    listen 443 ssl default_server;

    # Update with your SSL files. This is certbot genrated SSL details
    # Steps to generate cerbot SSL https://certbot.eff.org/lets-encrypt/ubuntufocal-nginx
    ssl_certificate /etc/letsencrypt/live/SOME_PROJECT_NAME/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/SOME_PROJECT_NAME/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    }

    server {
    if ($host = www.DOMAINNAME.com) {
    return 301 https://$host$request_uri;
    }

    if ($host = DOMAINNAME.com) {
    return 301 https://$host$request_uri;
    }

    listen 80 ;
    listen [::]:80 ;
    server_name www.DOMAINNAME.com DOMAINNAME.com;
    return 301 https://$host$request_uri;
    }