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.

HopelessN00b
  • 53,385
  • 32
  • 133
  • 208
Pamela
  • 187
  • 1
  • 13
  • [Administration panels are off topic](http://serverfault.com/help/on-topic). [Even the presence of an administration panel on a system,](http://meta.serverfault.com/q/6538/118258) because they [take over the systems in strange and non-standard ways, making it difficult or even impossible for actual system administrators to manage the servers normally](http://meta.serverfault.com/a/3924/118258), and tend to indicate low-quality questions from *users* with insufficient knowledge for this site. – HopelessN00b Mar 08 '15 at 18:34

2 Answers2

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;
    }
}
xofer
  • 3,052
  • 12
  • 19
  • Thanks. However, when I go to http://www.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, https://www.example.com:8081/, displays fine. It is only when I try going to https://www.example.com:8081/phpmyadmin that I get a "404 Not Found" page. – Pamela Aug 19 '14 at 00: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;
}
}
Pamela
  • 187
  • 1
  • 13