Enable HTTPS with SSL certificate in Nginx and update APP_URL

This commit is contained in:
vickytechkey 2026-09-08 22:47:35 +05:30
parent 8dca777f60
commit 9483685ffd

View file

@ -92,7 +92,7 @@ jobs:
fi
# Configure APP_URL and Database connection
sed -i 's|^APP_URL=.*|APP_URL=http://socialmedia.tradhox.com|g' .env
sed -i 's|^APP_URL=.*|APP_URL=https://socialmedia.tradhox.com|g' .env
sed -i 's/^DB_HOST=.*/DB_HOST=16.113.106.152/g' .env
sed -i 's/^DB_DATABASE=.*/DB_DATABASE=trypost/g' .env
sed -i 's/^DB_USERNAME=.*/DB_USERNAME=vignesh/g' .env
@ -101,7 +101,7 @@ jobs:
# Configure Facebook OAuth
sed -i 's|^FACEBOOK_CLIENT_ID=.*|FACEBOOK_CLIENT_ID=2105308916859392|g' .env
sed -i 's|^FACEBOOK_CLIENT_SECRET=.*|FACEBOOK_CLIENT_SECRET=79b51ed72514663f3629aa33610490f9|g' .env
sed -i 's|^FACEBOOK_CLIENT_REDIRECT=.*|FACEBOOK_CLIENT_REDIRECT=\"http://socialmedia.tradhox.com/accounts/facebook/callback\"|g' .env
sed -i 's|^FACEBOOK_CLIENT_REDIRECT=.*|FACEBOOK_CLIENT_REDIRECT=\"https://socialmedia.tradhox.com/accounts/facebook/callback\"|g' .env
# Ensure web server owns the files after composer finishes writing caches
sudo chown -R www-data:www-data storage bootstrap/cache
@ -116,40 +116,53 @@ jobs:
php artisan optimize:clear
# 6. Configure Nginx for socialmedia.tradhox.com
echo "Configuring Nginx..."
sudo tee /etc/nginx/sites-available/socialmedia.tradhox.com > /dev/null << 'EOF'
server {
listen 80;
listen [::]:80;
server_name socialmedia.tradhox.com;
root /var/www/trypost/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
EOF
if [ -f /etc/letsencrypt/live/socialmedia.tradhox.com/fullchain.pem ]; then
sudo tee /etc/nginx/sites-available/socialmedia.tradhox.com > /dev/null << 'EOF'
server {
server_name socialmedia.tradhox.com;
root /var/www/trypost/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
listen [::]:443 ssl;
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/socialmedia.tradhox.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/socialmedia.tradhox.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}
server {
listen 80;
listen [::]:80;
server_name socialmedia.tradhox.com;
return 301 https://$host$request_uri;
}
EOF
fi
sudo ln -sf /etc/nginx/sites-available/socialmedia.tradhox.com /etc/nginx/sites-enabled/
sudo rm -f /etc/nginx/sites-enabled/default