Welcome! Log In Create A New Profile


How should I create an alias outside the root directory in nginx?

Posted by dertin 
How should I create an alias outside the root directory in nginx?
January 30, 2018 02:50PM

I am trying to create a protected directory that is outside the documents in the root directory.

I tried to place an alias to a directory external to the root directory of the server, but I am having trouble responding to PHP scripts.

The error he shows me is "File not found."

/var/www/website.com/htdocs <---- (all files that are public) www.website.com
/var/www/website.com/admdb <---- (only private files) www.website.com/admdb

## Serves https://www.website.com
server {
server_name www.website.com;
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server ipv6only=on;

resolver valid=300s;

ssl_certificate /etc/letsencrypt/live/website.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/website.com/privkey.pem;

include /etc/nginx/snippets/diffie-hellman;

root /var/www/website.com/htdocs;

index index.php index.html index.htm;

include /etc/nginx/snippets/security;

location / {
try_files $uri $uri/ =404;

location /sendy {
access_log off;
error_log off;
rewrite ^/sendy/(l|t|w)/([a-zA-Z0-9\/]+)$ /sendy/$1.php?i=$2&$args;
rewrite ^/sendy/(u?n?subscribe)/(.*)$ /sendy/$1.php?i=$2&$args;
try_files $uri $uri/ $uri.php?$args;

location ^~ /admdb {

alias /var/www/website.com/admdb;

#auth_basic "Restricted Content";
#auth_basic_user_file /etc/nginx/.htpasswd;

location ~ \.php$ {
include /etc/nginx/fastcgi.conf;
fastcgi_param DOCUMENT_ROOT /var/www/website.com/admdb;

location ~ \.php$ {
include /etc/nginx/fastcgi.conf;


Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 151
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready