Benny's Shopware Notebook
  • Introduction
    • How to Get in Touch
  • ddev for Shopware
    • Less than 5 Minutes Install with ddev and Symfony Flex
    • Storefront and Admin Watchers with ddev
    • Message Queue Setup with ddev
    • Contribute with ddev
    • Performance Tweaks
    • RabbitMQ with ddev
    • phpstan pro with ddev
    • Fetch Media from Production or Staging Server
  • Hosting
    • Setting up a Cloud Server with ddev
    • How to Trouble-shoot and Evaluate Environment Variables
    • Media URLs Out Of Sync between Servers
    • RabbitMQ
    • Running Shopware CE with PaaS
    • SFTP-Users
    • Basic-Auth for Shopware 6 with nginx
    • How to Avoid Failed Systemd Units
    • JWT-Secrets as Environment Variables
  • Deployment
    • Close-to-Zero Downtime Deployment
    • Docker-Images for Deployment with Gitlab-Runners
    • PHP Cache Related Issues
  • Development
    • Patching the Core
    • How to Discover Available Updates?
    • Local Testing of Shopware Commercial Features
  • Administration
  • Database
  • Migration
    • Side Effects
Powered by GitBook
On this page

Was this helpful?

  1. Hosting

Basic-Auth for Shopware 6 with nginx

This page explains how to establish basic-auth for Shopware 6 when using nginx (instead of Apache).

Unlike Apache2, where basic-auth is set in the local .htaccess file, in nginx it is set in the server's vhosts file. The downside is that it is difficult to integrate into the CI/CD pipeline. The upside is that it is defined per server by definition and thus doesn't require CI/CD procedures to take care of what the deployment's target (e.g. production, staging, ...) is.

First of all, create an .htpasswd file suiting your needs. A variety of online tools exist for this task. If you have access to a Unix/Ubuntu system, the clean way to go is to run the hdpasswd command:

htpasswd   

htpasswd will prompt you for the basic auth password.

Then locate and edit the nginx vhost file. At its head, preceding the server section, add the following lines:

map $request_uri $auth_type {
  default "off";
  ~/api/* "off";
  ~* "";
}
...

The above code sets a variable $auth_type to either "off" or to "vanWittlaer Demo Site" (or any other text you chose). Further down in the vhost file, and inside the server section, add the following two lines:

...
auth_basic $auth_type;
auth_basic_user_file <path-to-your-htpasswd-file>/.htpasswd;
...
PreviousSFTP-UsersNextHow to Avoid Failed Systemd Units

Last updated 10 months ago

Was this helpful?