Skip to content
Menu
ChaoTic
  • Home
  • Python
  • APEX
  • PL/SQL
  • Oralce DB
  • Docker
  • OCI
  • Nginx
  • C#
  • Linux
  • JavaScript
  • Privacy Policy
ChaoTic

Config Nginx as Static file server

Posted on December 15, 2022July 25, 2023

Here is very rich video to learn Nginx

   server {
         listen 80;
         server_name static.chaoyu.nl;
         return 301 https://$server_name$request_uri;
   }
   server {
        listen       443 ssl;
        ssl_certificate "/sslcerts/certificate.crt";
        ssl_certificate_key "/sslcerts/certificate.key";
        ssl_session_cache shared:SSL:1m;
        ssl_session_timeout  10m;
        ssl_ciphers PROFILE=SYSTEM;
        ssl_prefer_server_ciphers on;

        server_name  static.chaoyu.nl
        root  /usr/share/nginx/;
        add_header Access-Control-Allow-Origin *;

        location /{
            include /etc/nginx/mime.types;
        }
        location /static-dev {
            include /etc/nginx/mime.types;
            alias  /usr/share/nginx/static/app_name1;
        }
        location /static-acc {
            include /etc/nginx/mime.types;
            alias  /usr/share/nginx/static/app_name2;

        }
        location /static-docker {
            include /etc/nginx/mime.types;
            alias  /usr/share/nginx/static/app_name3;
        }
   }

Config Linux user / groups to allow filezillar connection with key files

sudo groupadd sftpusergroup
sudo useradd mysftpuser

add user to group , append after its primary group ( which is not wat we want)

sudo usermod -a -G examplegroup exampleusername

we need to add sftpusergroup as the primary group, that way when a user create a folder all users in this groups would have the correct rights.

sudo usermod -g examplegroup exampleusername

Give mysftpuser a password

sudo passwd mysftpuser
sudo nano /etc/ssh/sshd_config

find PasswordAuthentication no and change no to yes for now.

restart sshd

sudo systemctl restart sshd.service
#login with newly created user 
ssh mysftpuser@your_server_ip
#enter pwd
#create .ssh folder
mkdir .ssh
#create authorized_keys file
nano authorized_keys
# put your public key here 
# check .ssh permission and authorized_keys permission
# they must match the below pic

Here is a handy web app to calculate from drwx to number

chmod 700 .ssh/
.ssh folder permission (700)
chmod 600 .ssh/authorized_keys
authorized_kyes permission (600)

Once file/folder permission is set correctly, we need to disable password authentication

sudo nano /etc/ssh/sshd_config
#find PasswordAuthentication yes and change to no
sudo systemctl restart sshd.service

Go to /usr/share/nginx with your opc/ or any user has root rights

# create new static folder and assign the group to sftpusergroup , which is mysftpuser's group. 
# this is needed if you want to write / upload js, images, css to this static folder via filezillar 
sudo mkdir static
sudo chgrp sftpusergroup static/ -R

If you have more users using this static file folder and more sub folders will be created, it is handly to set default group permission to RWX

sudo setfacl -R -dm g::rwx /yourfolder
# -R recrusive --recursive
# -d default 
# -m modity

man setfacl #to read more about 

Leave a Reply Cancel reply

You must be logged in to post a comment.

Recent Posts

  • Oracle APEX cheat sheets (on going)
  • Second Take on React Native – ReadCast
  • Switch Between APEX builder Authentication schemes
  • Use BitBucket Pipelines to Automate Oracle APEX deployment
  • MARKDown TEST

Categories

  • APEX
  • C#
  • chatgpt
  • Docker
  • JavaScript
  • Linux
  • Nginx
  • OCI
  • Oracle APEX
  • Oralce DB
  • PL/SQL
  • Python
  • Uncategorized
©2025 ChaoTic | Powered by SuperbThemes
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT
Scroll Up