Files
syno-scripts/Bash/TESTING/NGINX REVERSE PROXY.sh

86 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
# Variables
API_KEY="your_api_key"
API_URL="http://localhost:81/api/v1"
PRIVATE_KEY="/path/to/private-key.pem"
CERTIFICATE="/path/to/certificate.pem"
CHAIN="/path/to/chain.pem" # Optional
# Function to install Nginx Proxy Manager
install_nginx_proxy_manager() {
# Install dependencies
apt-get update
apt-get install -y curl gnupg2 lsb-release git sudo
# Install Node.js and Yarn
curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
apt-get update
apt-get install -y nodejs yarn
# Clone Nginx Proxy Manager repository
git clone https://github.com/jc21/nginx-proxy-manager /opt/nginx-proxy-manager
cd /opt/nginx-proxy-manager
# Install backend dependencies
cd backend
yarn install
# Configure MariaDB (assuming it's already installed and secured)
mysql -u root -p -e "CREATE DATABASE npm;"
mysql -u root -p -e "CREATE USER 'npm_user'@'localhost' IDENTIFIED BY 'password';"
mysql -u root -p -e "GRANT ALL PRIVILEGES ON npm.* TO 'npm_user'@'localhost';"
mysql -u root -p -e "FLUSH PRIVILEGES;"
# Configure backend environment
cp .env.example .env
# Edit .env file with appropriate database credentials and other settings
# Start backend server
yarn start &
# Install frontend dependencies
cd ../frontend
yarn install
# Build frontend
yarn build
# Configure Nginx or other web server to serve frontend
# Optionally, set up SSL certificates in the frontend configuration
# Wait for backend to start (adjust sleep time as needed)
sleep 10
# Import SSL certificate using API
import_certificate
}
# Function to import SSL certificate using API
import_certificate() {
# Create JSON data for certificate import
certificate_data=$(cat <<EOF
{
"privateKey": "$(cat $PRIVATE_KEY)",
"certificate": "$(cat $CERTIFICATE)",
"chain": "$(cat $CHAIN)"
}
EOF
)
# Make API request to import certificate
curl -X POST \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d "$certificate_data" \
"$API_URL/certificates"
echo "Certificate imported successfully."
}
# Main script execution
install_nginx_proxy_manager