-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
1,826 additions
and
7,590 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# FastAPI (Gunicorn) | ||
|
||
--bind 0.0.0.0:8000 essentially tells Gunicorn to listen on all available network interfaces on port 8000. This is a common configuration when you want your Gunicorn server to be accessible from external sources, such as when deploying a web application. | ||
|
||
For example, if you deploy a Flask, Django or FastAPI application with Gunicorn using this bind option, your application will be accessible over HTTP at http://your_server_ip:8000. | ||
|
||
|
||
|
||
## Gunicorn YAML Config | ||
|
||
```yaml | ||
|
||
workers = 3 # number of workers Gunicorn will spawn | ||
|
||
bind = '127.0.0.1:8000' # this is where you declare on which address your | ||
|
||
|
||
# gunicorn app is running. | ||
# Basically where Nginx will forward the request to | ||
|
||
pidfile = '/var/run/gunicorn/mysite.pid' # create a simple pid file for gunicorn. | ||
|
||
user = 'user' # the user gunicorn will run on | ||
|
||
daemon = True # this is only to tell gunicorn to deamonize the server process | ||
|
||
errorlog = '/var/log/gunicorn/error-mysite.log' # error log | ||
|
||
accesslog = '/var/log/gunicorn/access-mysite.log' # access log | ||
|
||
proc_name = 'gunicorn-mysite' # the gunicorn process name | ||
``` |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
# Nginx | ||
|
||
[Nginx](https://nginx.org/) is a powerful and widely-used open-source web server, reverse proxy server, and load balancer. Known for its efficiency and low resource usage, Nginx excels in handling concurrent connections and serving static content, making it a popular choice for high-traffic websites. | ||
|
||
## Installation | ||
|
||
```bash | ||
sudo apt update | ||
sudo apt install nginx | ||
``` | ||
|
||
|
||
## Configuration | ||
|
||
Nginx's main configuration file is typically located at `/etc/nginx/nginx.conf`. Additional configurations for specific sites or applications are placed in the `/etc/nginx/sites-available/` directory. | ||
|
||
### Basic Configuration | ||
|
||
1. **Start Nginx:** | ||
|
||
```bash | ||
sudo systemctl start nginx | ||
``` | ||
|
||
2. **Enable Nginx to start on boot:** | ||
|
||
```bash | ||
sudo systemctl enable nginx | ||
``` | ||
|
||
#### Server Block (Virtual Host) | ||
|
||
To configure a server block for a specific domain or application, create a new configuration file within the `sites-available` directory and create a symbolic link to `sites-enabled`: | ||
|
||
```bash | ||
sudo nano /etc/nginx/sites-available/example.com | ||
``` | ||
|
||
Example configuration: | ||
|
||
```nginx | ||
server { | ||
listen 80; | ||
server_name example.com www.example.com; | ||
location / { | ||
root /var/www/html; | ||
index index.html; | ||
} | ||
} | ||
``` | ||
|
||
Create a symbolic link: | ||
|
||
```bash | ||
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/ | ||
``` | ||
|
||
Restart Nginx to apply changes: | ||
|
||
```bash | ||
sudo systemctl restart nginx | ||
``` | ||
|
||
This basic example serves files from `/var/www/html` for the specified domain. | ||
|
||
#### More advanced configurations | ||
[Nginx documentation](https://nginx.org/en/docs/). | ||
|
||
! tip "Remember to test your configuration before restarting Nginx" | ||
|
||
```bash | ||
sudo nginx -t | ||
``` | ||
|
||
|
||
## Restricting files using Nginx. | ||
Lets restrict files in two locations: (`/admin`, `/private`). | ||
|
||
|
||
1. **Create Password Files:** | ||
Use the `htpasswd` tool to create password files for each location: | ||
|
||
```bash | ||
sudo htpasswd -c /etc/nginx/.htpasswd_admin admin_user | ||
|
||
sudo htpasswd -c /etc/nginx/.htpasswd_private private_user | ||
``` | ||
! warn "You will be prompted to enter and confirm passwords for each user." | ||
|
||
2. **Configure Nginx:** | ||
Update your Nginx configuration: | ||
|
||
```nginx | ||
server { | ||
listen 80; | ||
server_name example.com; | ||
location /admin { | ||
auth_basic "Admin Area"; | ||
auth_basic_user_file /etc/nginx/.htpasswd_admin; | ||
# Your configuration for the admin area goes here | ||
} | ||
location /private { | ||
auth_basic "Private Area"; | ||
auth_basic_user_file /etc/nginx/.htpasswd_private; | ||
# Your configuration for the private area goes here | ||
} | ||
... | ||
} | ||
``` | ||
|
||
|
||
3. **Test and Reload Nginx:** | ||
Test the Nginx configuration and reload: | ||
|
||
```bash | ||
sudo nginx -t | ||
sudo systemctl reload nginx | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# CRON update github repositories. | ||
|
||
We have a number of repositories on our VM that we would wish to keep up to date. | ||
|
||
To ensure this is the case we run a timed job (CRON) which checks and updates a list of repositories. | ||
|
||
The basic code required to accomplish this can be found: | ||
|
||
```bash | ||
#!/bin/bash | ||
|
||
# Define the list of repositories | ||
repositories=( | ||
"$HOME/repo1-location" | ||
"$HOME/repos/repo2-location" | ||
... | ||
) | ||
|
||
# Specify the branch to check for updates | ||
branch="main" | ||
|
||
# Specify the log file with date | ||
log_file="$HOME/.logs/repo_update_$(date +\%Y\%m\%d).log" | ||
|
||
# Specify the backup folder | ||
backup_folder="$HOME/backup" | ||
|
||
# Create the backup folder if it doesn't exist | ||
mkdir -p "$backup_folder" | ||
|
||
# Loop through each repository and update if changes are found | ||
for repo in "${repositories[@]}"; do | ||
echo "------------------------------" | ||
echo "Checking for updates in $repo" | ||
|
||
# Navigate to the repository | ||
cd "$repo" || exit 1 | ||
|
||
# Fetch remote changes | ||
git fetch origin "$branch" | ||
|
||
# Check if there are any changes on the specified branch | ||
if [[ $(git rev-list HEAD..origin/"$branch" --count) -gt 0 ]]; then | ||
echo "Updating $repo" | ||
|
||
# Create a backup with date timestamp | ||
backup_file="$backup_folder/$(basename "$repo")_backup_$(date +\%Y\%m\%d_\%H\%M\%S).tar.gz" | ||
tar -czf "$backup_file" . >> "$log_file" 2>&1 | ||
|
||
# Pull changes and force overwrite conflicts | ||
git pull origin "$branch" --force >> "$log_file" 2>&1 | ||
|
||
# Log the status of the update with the date | ||
echo "$(date): Update status for $repo: Success" >> "$log_file" | ||
echo "$(date): Repository backed up to $backup_file" >> "$log_file" | ||
else | ||
echo "No updates found in $repo" | ||
|
||
# Log the status of the update with the date | ||
echo "$(date): Update status for $repo: No updates found" >> "$log_file" | ||
fi | ||
|
||
# Return to the script's directory | ||
cd - || exit 1 | ||
done | ||
|
||
``` |
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.