Nginx Server Block Port 8081 Path to Root Folder [closed]

I'm trying to password protect all of port 8081 on my Nginx server. The only thing this port is used for is PhpMyAdmin. When I navigate to https://www.example.com:8081, I successfully get the default Nginx welcome page. However, when I try navigating to the PhpMyAdmin directory, https://www.example.com:8081/phpmyadmin, I get a "404 Not Found" page.

Permission for my htpasswd file is set to 644.

Here is the code for my server block:

server {
listen 8081;
server_name example.com www.example.com;
root /usr/share/phpmyadmin;
auth_basic            "Restricted Area";
auth_basic_user_file  htpasswd;
}

I have also tried entirely commenting out #root /usr/share/phpmyadmin; However, it doesn't make any difference.

Is my problem confined to using the incorrect root path? If so, how can I find the root path for PhpMyAdmin?

If it makes any difference, I'm using Ubuntu 14.04.1 LTS with Nginx 1.4.6 and ISPConfig 3.0.5.4p3.


Solution 1:

SSL is not enabled in this server. Try http://www.example.com:8081/

To get SSL to work, you'll need something like:

listen 8081 ssl;
ssl_certificate /path/to/your.crt;
ssl_certificate_key /path/to/your.key;
error_page 497 https://$host:$server_port$request_uri;

The error page line will redirect http://... to https://...

EDIT: here's a full server block that works for me -- I started testing this before I saw your answer which includes the PHP block :)

server {
    listen 8081 ssl;
    ssl_certificate /etc/nginx/server.crt;
    ssl_certificate_key /etc/nginx/server.key;
    error_page 497 https://$host:$server_port$request_uri;

    server_name example.com www.example.com;
    root /usr/share/phpmyadmin;

    location / {
        auth_basic "Restricted Area";
        auth_basic_user_file htpasswd;

        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors on;
    }
}