Browse Source

chore: configured Nginx Dockerfile, updated PHP requirements in the PHP Dockerfile, and made other changes

Junior L. Botelho (JLB) 2 years ago
parent
commit
3cbb36eb66

+ 2 - 2
Dockerfile

@@ -1,7 +1,7 @@
 # syntax = edrevo/dockerfile-plus
 ARG VERSION="3.17"
 FROM alpine:${VERSION} AS runner
-WORKDIR "/home/librex"
+WORKDIR "/var/www/html"
 
 # Docker metadata contains information about the maintainer, such as the name, repository, and support email
 # Please add any necessary information or correct any incorrect information
@@ -24,7 +24,7 @@ ARG DOCKER_SCRIPTS="docker"
 ENV TZ="America/New_York"
 
 # Include docker scripts, docker images, and the 'GNU License' in the Librex container
-ADD "." "/home/librex"
+ADD "." "/var/www/html"
 
 # Set permissions for script files as executable scripts inside 'docker/scripts' directory
 RUN   chmod u+x "${DOCKER_SCRIPTS}/php/prepare.sh" &&\

+ 2 - 1
docker/attributes.sh

@@ -7,6 +7,7 @@
 # If these locations do not already exist within the Docker container, they will be created
 export CONFIG_PHP_TEMPLATE="$(pwd)/config.php"
 export CONFIG_OPEN_SEARCH_TEMPLATE="$(pwd)/opensearch.xml"
+export CONFIG_NGINX_TEMPLATE="/etc/nginx/http.d/librex.conf"
 
 # Configure 'opensearch.xml' with Librex configuration metadata, such as the encoding and the host that stores the site
 # These configurations will replace the 'opensearch.xml' inside '.dockers/templates' for the best setup for your instance
@@ -14,7 +15,7 @@ export OPEN_SEARCH_TITLE=${OPEN_SEARCH_TITLE:-"LibreX"}
 export OPEN_SEARCH_DESCRIPTION=${OPEN_SEARCH_DESCRIPTION:-"Framework and javascript free privacy respecting meta search engine"}
 export OPEN_SEARCH_ENCODING=${OPEN_SEARCH_ENCODING:-"UTF-8"}
 export OPEN_SEARCH_LONG_NAME=${OPEN_SEARCH_LONG_NAME:-"LibreX Search"}
-export OPEN_SEARCH_HOST=${OPEN_SEARCH_HOST:-"http://localhost:80"}
+export OPEN_SEARCH_HOST=${OPEN_SEARCH_HOST:-"127.0.0.1"}
 
 # Replace the 'config.php' script, which contains the most common search engine configurations, with these environment setups
 # These environment setups can be found in 'config.php', and the default configurations can be useful for most use cases

+ 3 - 5
docker/php/php.dockerfile

@@ -7,7 +7,7 @@ ENV OPEN_SEARCH_TITLE="LibreX"
 ENV OPEN_SEARCH_DESCRIPTION="Framework and javascript free privacy respecting meta search engine"
 ENV OPEN_SEARCH_ENCODING="UTF-8"
 ENV OPEN_SEARCH_LONG_NAME="LibreX Search"
-ENV OPEN_SEARCH_HOST="http://localhost:80"
+ENV OPEN_SEARCH_HOST="127.0.0.1"
 
 # Replace the 'config.php' script, which contains the most common search engine configurations, with these environment setups
 # These environment setups can be found in 'config.php', and the default configurations can be useful for most use cases
@@ -49,12 +49,10 @@ ENV CURLOPT_VERBOSE=false
 
 # Install PHP-FPM using Alpine's package manager, apk
 # Configure PHP-FPM to listen on a Unix socket instead of a TCP port, which is more secure and efficient
-RUN apk add php7 php7-fpm abuild-rootbld --no-cache --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing &&\
+RUN apk add php7 php7-fpm php7-dom php7-curl php7-xml abuild-rootbld --no-cache --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing &&\
     sed -i 's/^\s*listen = 127.0.0.1:9000/listen = \/run\/php-fpm\/php-fpm.sock/' ${WWW_CONFIG} &&\
     sed -i 's/^\s*;\s*listen.owner = nobody/listen.owner = nginx/' ${WWW_CONFIG} &&\
     sed -i 's/^\s*;\s*listen.group = nobody/listen.group = nginx/' ${WWW_CONFIG} &&\
     sed -i 's/^\s*;\s*listen.mode = 0660/listen.mode = 0660/' ${WWW_CONFIG}
-
-RUN echo $(pwd)
-
+    
 RUN docker/php/prepare.sh

+ 2 - 2
docker/php/prepare.sh

@@ -5,8 +5,8 @@ source "docker/attributes.sh"
 
 # The lines below will replace the environment variables in the templates with the corresponding variables listed above. To accomplish this, the GNU 'envsubst' package will be used
 # Although not recommended (if you do not know what you are doing), you still have the option to add new substitution file templates using any required environment variables
-[[ ! -s ${CONFIG_PHP_TEMPLATE} ]] && cat 'docker/php/config.php' | envsubst | AwkTrim > ${CONFIG_PHP_TEMPLATE};
-[[ ! -s ${CONFIG_OPEN_SEARCH_TEMPLATE} ]] && cat 'docker/php/opensearch.xml' | envsubst | AwkTrim > ${CONFIG_OPEN_SEARCH_TEMPLATE};
+[[ ! -s ${CONFIG_PHP_TEMPLATE} ]] && cat 'docker/php/config.php' | envsubst > ${CONFIG_PHP_TEMPLATE};
+[[ ! -s ${CONFIG_OPEN_SEARCH_TEMPLATE} ]] && cat 'docker/php/opensearch.xml' | envsubst > ${CONFIG_OPEN_SEARCH_TEMPLATE};
 
 # If it is empty or proxy is not enabled, we are using sed to delete
 # any line that contains the string 'CURLOPT_PROXY' or 'CURLOPT_PROXYTYPE'

+ 26 - 0
docker/server/fastcgi.conf

@@ -0,0 +1,26 @@
+# These settings should work well for serving as a front-end of many search engines
+# on our PHP website. However, we may need to adjust them based on our specific requirements.
+fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
+fastcgi_param QUERY_STRING          $query_string;
+fastcgi_param REQUEST_METHOD        $request_method;
+fastcgi_param CONTENT_TYPE          $content_type;
+fastcgi_param CONTENT_LENGTH        $content_length;
+
+fastcgi_param SCRIPT_NAME           $fastcgi_script_name;
+fastcgi_param REQUEST_URI           $request_uri;
+fastcgi_param DOCUMENT_URI          $document_uri;
+fastcgi_param DOCUMENT_ROOT         $document_root;
+fastcgi_param SERVER_PROTOCOL       $server_protocol;
+
+fastcgi_param GATEWAY_INTERFACE     CGI/1.1;
+fastcgi_param SERVER_SOFTWARE       nginx/$nginx_version;
+
+fastcgi_param REMOTE_ADDR           $remote_addr;
+fastcgi_param REMOTE_PORT           $remote_port;
+fastcgi_param SERVER_ADDR           $server_addr;
+fastcgi_param SERVER_PORT           $server_port;
+fastcgi_param SERVER_NAME           $server_name;
+
+# PHP only, required if PHP was built with --enable-force-cgi-redirect
+fastcgi_param HTTPS                 $https if_not_empty;
+fastcgi_param REDIRECT_STATUS       200;

+ 1 - 2
docker/server/nginx.conf

@@ -12,7 +12,6 @@ server {
     location ~ \.php$ {
         fastcgi_pass   unix:/run/php-fpm/php-fpm.sock;
         fastcgi_index  index.php;
-        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
-        include        fastcgi_params;
+        include        fastcgi.conf;
     }
 }

+ 9 - 1
docker/server/nginx.dockerfile

@@ -1 +1,9 @@
-RUN echo "Hello Nginx"
+RUN apk add nginx
+
+ADD "docker/server/fastcgi.conf" /etc/nginx/fastcgi.conf
+ADD "docker/server/nginx.conf" /etc/nginx/http.d/librex.conf
+
+RUN chmod u+x "/etc/nginx/fastcgi.conf" &&\
+    chmod u+x "/etc/nginx/http.d/librex.conf"
+
+RUN docker/server/prepare.sh

+ 8 - 0
docker/server/prepare.sh

@@ -0,0 +1,8 @@
+#!/bin/sh
+
+# Load all environment variables from 'attributes.sh' using the command 'source /path/attributes.sh'
+source "docker/attributes.sh"
+
+# The lines below will replace the environment variables in the templates with the corresponding variables listed above. To accomplish this, the GNU 'envsubst' package will be used
+# Although not recommended (if you do not know what you are doing), you still have the option to add new substitution file templates using any required environment variables
+exec cat 'docker/server/nginx.conf' | envsubst > ${CONFIG_NGINX_TEMPLATE};