From 9ac289a9696abe952ad6a76bec7cb0d847017e7f Mon Sep 17 00:00:00 2001 From: 0x5f3 <104367919+0x5f3@users.noreply.github.com> Date: Fri, 5 Aug 2022 13:21:53 +0000 Subject: [PATCH] replace lighttd with nginx --- Dockerfile | 16 +++++++--------- dockerfiles/start.sh | 6 ++++-- install/default | 12 ++++++++++++ 3 files changed, 23 insertions(+), 11 deletions(-) create mode 100644 install/default diff --git a/Dockerfile b/Dockerfile index da69ee08..8270667c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,15 +7,14 @@ ENV USER=pi USER_ID=1000 USER_GID=1000 TZ=Europe/London PORT=20211 # Todo, do we still need all these packages? I can already see sudo which isn't needed RUN apt-get update \ - && apt-get install --no-install-recommends ca-certificates curl libwww-perl arp-scan perl apt-utils cron sudo lighttpd php php-cgi php-fpm php-sqlite3 sqlite3 dnsutils net-tools python3 iproute2 nmap python3-pip zip -y \ + && apt-get install --no-install-recommends ca-certificates curl libwww-perl arp-scan perl apt-utils cron sudo nginx-light php php-cgi php-fpm php-sqlite3 sqlite3 dnsutils net-tools python3 iproute2 nmap python3-pip zip -y \ && pip3 install requests \ && update-alternatives --install /usr/bin/python python /usr/bin/python3 10 \ && apt-get clean autoclean \ && apt-get autoremove \ && rm -rf /var/lib/apt/lists/* \ && rm -rf /var/www/html \ - && ln -s /home/pi/pialert/front /var/www/html \ - && lighttpd-enable-mod fastcgi-php + && ln -s /home/pi/pialert/front /var/www/html # now creating user @@ -30,14 +29,13 @@ RUN groupadd --gid "${USER_GID}" "${USER}" && \ COPY . /home/pi/pialert # Pi.Alert -RUN python /home/pi/pialert/back/pialert.py update_vendors \ - && sed -ie 's/= 80/= '${PORT}'/g' /etc/lighttpd/lighttpd.conf \ +RUN python /home/pi/pialert/back/pialert.py update_vendors \ + && rm /etc/nginx/sites-available/default \ + && ln -s /home/pi/pialert/install/default /etc/nginx/sites-available/default \ + && sed -ie 's/listen 80/listen '${PORT}'/g' /etc/nginx/sites-available/default \ && (crontab -l 2>/dev/null; cat /home/pi/pialert/install/pialert.cron) | crontab - # it's easy for permissions set in Git to be overridden, so doing it manually RUN chmod -R a+rxw /home/pi/pialert/ -# keep backward-compatibility with old links using /pialert as a base (remove in 2023) -RUN ln -s /home/pi/pialert/front /var/www/html/pialert - -CMD ["/home/pi/pialert/dockerfiles/start.sh"] +CMD ["/home/pi/pialert/dockerfiles/start.sh"] \ No newline at end of file diff --git a/dockerfiles/start.sh b/dockerfiles/start.sh index 247ba2d4..67099939 100755 --- a/dockerfiles/start.sh +++ b/dockerfiles/start.sh @@ -7,9 +7,11 @@ if [ -n "${TZ}" ]; then sed -ie "s|Europe/Berlin|${TZ}|g" /home/pi/pialert/config/pialert.conf crontab < /home/pi/pialert/install/pialert.cron fi + if [ -n "${PORT}" ]; then - sed -ie 's/= 20211/= '${PORT}'/g' /etc/lighttpd/lighttpd.conf + sed -ie 's/listen 20211/listen '${PORT}'/g' /etc/nginx/sites-available/default fi -/etc/init.d/lighttpd start +/etc/init.d/php7.4-fpm start +/etc/init.d/nginx start cron -f diff --git a/install/default b/install/default new file mode 100644 index 00000000..1e235e9c --- /dev/null +++ b/install/default @@ -0,0 +1,12 @@ +server { + listen 80 default_server; + root /var/www/html; + index index.php; + + location ~* \.php$ { + fastcgi_pass unix:/run/php/php7.4-fpm.sock; + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param SCRIPT_NAME $fastcgi_script_name; + } +} \ No newline at end of file