Skip to content

Instantly share code, notes, and snippets.

@dwdraju
Last active March 5, 2019 16:30
Show Gist options
  • Save dwdraju/c7652bc08d436d09936e410617886d6d to your computer and use it in GitHub Desktop.
Save dwdraju/c7652bc08d436d09936e410617886d6d to your computer and use it in GitHub Desktop.
Nginx htaccess block

Generate password & user

sudo sh -c "echo -n 'user:' >> /etc/nginx/.htpasswd"
sudo sh -c "openssl passwd -apr1 >> /etc/nginx/.htpasswd"
cat /etc/nginx/.htpasswd

Nginx conf

location / {
        try_files $uri $uri/ =404;
        auth_basic "Restricted Content";
        auth_basic_user_file /etc/nginx/.htpasswd;
    }

Generate password & user

sudo sh -c "echo -n 'user:' >> /etc/nginx/.htpasswd"
sudo sh -c "openssl passwd -apr1 >> /etc/nginx/.htpasswd"
cat /etc/nginx/.htpasswd

Nginx conf

location / {
        try_files $uri $uri/ =404;
        auth_basic "Restricted Content";
        auth_basic_user_file /etc/nginx/.htpasswd;
    }

Apache

<VirtualHost *:443> 

 ServerName   example.com
 DocumentRoot /var/www/FrontEnd/dist
 ErrorLog     /var/www/FrontEnd/logs/error.log
 CustomLog    /var/www/FrontEnd/logs/access.log combined

 SSLEngine on
 SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
 SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem

<Directory /var/www/FrontEnd/dist>
AllowOverride All
  Options +SymLinksIfOwnerMatch
  AllowOverRIde All
  Order deny,allow
  AuthType Basic
        AuthName "Restricted Content"
        AuthUserFile "/etc/apache2/.htpasswd"
        Require valid-user
  DirectoryIndex index.html index.php
</Directory>

<Directory /var/www/FrontEnd/public>
AllowOverride All
  Options +SymLinksIfOwnerMatch
Order deny,allow
  DirectoryIndex index.html index.php
</Directory>

</VirtualHost>

<VirtualHost *:443>

 ServerName   cms.example.com
 DocumentRoot /var/www/BackEnd/public
 ErrorLog     /var/www/BackEnd/logs/error.log
 CustomLog    /var/www/BackEnd/logs/access.log combined

 SSLEngine on
 SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
 SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem

<Directory /var/www/BackEnd/public>
  Options +SymLinksIfOwnerMatch
  AllowOverRide All
  Order deny,allow
  DirectoryIndex index.html  index.php
</Directory>

</VirtualHost>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment