Have tried the answer in How to: Password Protect Azure App service but in my wordpress-linux-appservice container it is not working. Main issue i found is nginx service is stopped while my wordpress content are being served without any issue.
1df0ea390fee:~# netstat -tlnp | grep -E '(:80|:443)'
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 232/nginx: master p
1df0ea390fee:~# ^C
1df0ea390fee:~# rc-service nginx status
* status: stopped
Tried the answer for Linux Azure WebApp solution…but running into the issue , nginx is stopped.
Syed Asif Hashmi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
To password protect a directory in your Azure Linux WebApp running a WordPress container with Nginx, you need to create a .htpasswd
file and update your nginx.conf to use this file for authentication.
FROM wordpress:latest
RUN apt-get update && apt-get install -y lsb-release apt-transport-https ca-certificates wget gnupg gnupg2 apache2-utils &&
wget -q https://packages.sury.org/php/apt.gpg -O- | apt-key add - &&
echo "deb https://packages.sury.org/php/ $(lsb-release -sc) main" > /etc/apt/sources.list.d/php.list &&
apt-get update && apt-get install -y nginx supervisor php7.4-fpm
RUN rm /etc/nginx/sites-enabled/default
COPY nginx.conf /etc/nginx/sites-available/wordpress
RUN ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
EXPOSE 80 443
CMD ["supervisord", "-n"]
Update your nginx.conf to include the directives for HTTP Basic Authentication
server {
listen 80;
server_name _;
root /var/www/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php$is_args$args;
auth_basic "Restricted Content";
auth_basic_user_file /etc/nginx/.htpasswd;
}
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /.ht {
deny all;
}
}
edit your supervisord.conf
[supervisord]
nodaemon=true
[program:nginx]
command=/usr/sbin/nginx -g "daemon off;"
stdout_logfile=/var/log/nginx/access.log
stderr_logfile=/var/log/nginx/error.log
autorestart=true
[program:php-fpm]
command=/usr/sbin/php-fpm7.4
stdout_logfile=/var/log/php-fpm.log
stderr_logfile=/var/log/php-fpm.log
autorestart=true
Rebuild the image with the updated Dockerfile and run the docker container with the newly built image
docker build -t wordpress-nginx .
docker run -d -p 8081:80 wordpress-nginx
Set Up HTTP Basic Authentication Inside the Container
docker exec -it <container_id> /bin/bash