FIX: #0 Use symlink and root-based routing for Nginx to bypass alias bugs
All checks were successful
Deploy Beta (NATIVE) / deploy (push) Successful in 49s

This commit is contained in:
vickytechkey 2026-08-19 19:06:03 +05:30
parent daade735c9
commit 9499106180

View file

@ -1,13 +1,30 @@
import os import os
import subprocess
# Create symlink from /var/www/html/dolibarrbeta to the actual htdocs folder
symlink_path = '/var/www/html/dolibarrbeta'
target_path = '/home/ubuntu/dolibarrbeta/htdocs'
try:
if os.path.islink(symlink_path) or os.path.exists(symlink_path):
os.remove(symlink_path)
os.symlink(target_path, symlink_path)
print(f"Created symlink {symlink_path} -> {target_path}")
except Exception as e:
# If standard user cannot do it, let's print message or handle it via subprocess in bash
print(f"Symlink creation message: {e}")
filepath = '/etc/nginx/sites-available/default' filepath = '/etc/nginx/sites-available/default'
if os.path.exists(filepath): if os.path.exists(filepath):
content = open(filepath).read() content = open(filepath).read()
if 'location ^~ /dolibarrbeta' not in content:
idx = content.find('location / {') # Remove any old alias block if it exists
if idx != -1: old_block_marker = 'location ^~ /dolibarrbeta'
block = r"""location ^~ /dolibarrbeta { if old_block_marker in content:
# We can clean up the configuration file by removing the old block
# To be safe, we will rewrite the file cleanly with the new root block
content = content.replace(r''' location ^~ /dolibarrbeta {
alias /home/ubuntu/dolibarrbeta/htdocs; alias /home/ubuntu/dolibarrbeta/htdocs;
index index.php; index index.php;
try_files $uri $uri/ /dolibarrbeta/index.php?$args; try_files $uri $uri/ /dolibarrbeta/index.php?$args;
@ -17,6 +34,22 @@ if os.path.exists(filepath):
fastcgi_param SCRIPT_FILENAME $request_filename; fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock; fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
} }
}''', '')
# Insert the new correct root-based location block
if 'location /dolibarrbeta' not in content:
idx = content.find('location / {')
if idx != -1:
block = r"""location /dolibarrbeta {
root /var/www/html;
index index.php;
try_files $uri $uri/ /dolibarrbeta/index.php?$args;
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
}
} }
""" """