0

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.

1

2 Answers 2

2

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;
    }
}
1
  • Thanks. However, when I go to example.com:8081, I get "400 Bad Request The plain HTTP request was sent to HTTPS port". Doesn't that mean that SSL is enabled? The SSL version, example.com:8081, displays fine. It is only when I try going to example.com:8081/phpmyadmin that I get a "404 Not Found" page.
    – Pamela
    Aug 19, 2014 at 0:34
0

Thanks to masegaloeh for the following solution:

The solution is adding php-fpm section like this:

server {
listen 8081;
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/lib/php5-fpm/web11.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
}
}

Not the answer you're looking for? Browse other questions tagged .