8 Posts
  • Published Question

    NGINX rewrite script

    Hi, Sometimes I've to add hundreds of redirects to my NGINX server block. Such a script could definitely make my work easier. I didn't find ready-made solutions. I'm writing a script that gets addresses from a file an...
    Accepted Answer: Hi there, There are probably multiple ways to do it, but I would personally use a for loop to loop through each of the lines fo the file and then use printf to construct the redirect rule as follows: ```bash !/bin/bas...
    1 By MichalGiza Linux Commands Nginx
  • Published Question

    PHP compiling errors after install from ondrej/php repository

    Hi, I've been using ppa:ondrej/php repository for many months, but today, after installing PHP 8.0 and 7.4 on a new fresh server, I noticed the following error: PHP message: PHP Warning: preg_match(): Compilation fa...
    1 By MichalGiza PHP Ubuntu 20.04
  • Published Question

    Bash script with cat and $1

    Hello, I am writing a script which, among other things, generates Nginx configuration. Unfortunately, I ran into a problem. In Nginx config, I need to type $1. I use the following method for this: cat > /etc/nginx/si...
    Accepted Answer: Hello, What you could do is just use a backtick to escape the dollar sign: cat > /etc/nginx/sites-available/website <<EOL ... rewrite ^/api/?(.*)$ /web/api.php?url=<^>\<^>$1 last; ... EOL Hope that this helps Regard...
    1 By MichalGiza Linux Commands
  • Published Question

    Exclude lines with directory path

    Hello, I have a TXT file that contains the following example data: ./aa ./bb/data ./cc/files/docs I need to remove all lines from it that contain subdirectories. So in the example above, only the first line should rem...
    Accepted Answer: Hello, If I get this correctly, you want to have only the base directories without the subdirectories. This could be achieved with awk: cat old.txt | awk -F'/' '{ print $2 }' | sort | uniq Output: aa bb cc Regard...
    2 By MichalGiza Linux Commands
  • Published Question

    Exception for IP in Basic Auth on NGINX

    Hi, do you know a working way to set an exception for an IP address in NGINX? I tried with satisfy and @geolocation but it doesn't work. I am using version 1.18.0. Regards
    1 By MichalGiza Nginx Security
  • Published Answer

    Is it possible to host a python application on DO?

    It depends. You can use a server implemented in Python or create a proxy in Apache/Nginx. […
    By MichalGiza
  • Published Answer

    Can not connect message in web browser with dns

    Do you set ServerName in your virtual host configuration?
    By MichalGiza
  • Published Question

    PHP connection to MongoDB cluster

    Hello, I've difficulties with connection to MongoDB cluster on DigitalOcean by PHP. As we know, we have to use SSL, but I don't know how. My code is as follows: ``` <?php requireonce _DIR__ . "/vendor/autoload.php"; $...
    1 By MichalGiza MongoDB PHP