# Nginx SSL conf to access phpMyAdmin

**URL:** <https://www.ruby-forum.com/t/nginx-ssl-conf-to-access-phpmyadmin/188202>\
**Category:** NGINX\
**Created:** [May 7, 2010, 3:31pm UTC](https://www.ruby-forum.com/t/nginx-ssl-conf-to-access-phpmyadmin/188202 "2010-05-07T15:31:39Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ideanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/71e660/32.png) [@ideanet](https://www.ruby-forum.com/u/ideanet)\
**Post date:** [May 7, 2010, 3:31pm UTC](https://www.ruby-forum.com/t/nginx-ssl-conf-to-access-phpmyadmin/188202/1 "2010-05-07T15:31:39Z")

</div>

Hi,  
I have some trouble to configure correctly the access to phpMyAdmin via  
SSL.

1. problem: when i call the URL [https://mydomain.com/phpmyadmin/](https://mydomain.com/phpmyadmin/) I don’t  
have access.
2. problem: If I call the URL [https://mydomain.com/phpmyadmin/index.php](https://mydomain.com/phpmyadmin/index.php),  
I see the login page. I enter the account and password and after I’m  
redirected to the port 443 ([http://mydomain.com:443/phpmyadmin/](http://mydomain.com:443/phpmyadmin/)) with  
the message:

400 Bad Request  
The plain HTTP request was sent to HTTPS port

At this point, if I press the back button of the browser and reload the  
login page, I can enter on the phpMyAdmin.

I read that is needed the conf “fastcgi\_param HTTPS on;”, that I have  
included on my SSL section, but doesn’t have any effect…

Here my SSL conf:

[i]server {  
listen 443;  
server\_name [mydomain.com](http://mydomain.com);  
server\_tokens off;  
root /var/www/html;

```
            ssl on;
            ssl_certificate /etc/nginx/mydomain.crt;
            ssl_certificate_key /etc/nginx/mydomain.key;

            keepalive_timeout 70;
            add_header Front-End-Https on;

            client_max_body_size 50M;

            fastcgi_param HTTPS on;

            ## Protect some directory and files
            location ~ 

```

(^/(app/|includes/|lib/|/pkginfo/|var/|report/config.xml)|/.svn/|/.hta.+)  
{  
deny all;  
}

```
            ## Specific SSL log files
            access_log /var/log/nginx/ssl.access.log;
            error_log /var/log/nginx/ssl.error.log;

            ## this rewrites all the requests to the 

```

maintenance.html  
if (-f $document\_root/system/maintenance.html) {  
rewrite ^(.\*)$ /system/maintenance.html  
last;  
break;  
}

```
            ## Handle all .php files, /downloader and /report
            location ~ (\.php|/downloader/?|/report/?)$ {
                    if ($request_uri ~ /(downloader|report)$){
                            # no trailing /, redirecting
                            rewrite ^(.*)$ $1/ permanent;
                    }

                    fastcgi_index index.php;
                    include /etc/nginx/fastcgi_params;
                    fastcgi_param SCRIPT_FILENAME 

```

$document\_root$fastcgi\_script\_name;

```
                    if (-e $request_filename) { # check if requested 

```

path exists  
fastcgi\_pass backend;  
}

```
            }

            ## Magento specific configuration
            location / {
                    # set expire headers
                    if ($request_uri ~* 

```

“.(ico|css|js|gif|jpe?g|png)$”) {  
expires max;  
}

```
                    # set fastcgi settings, not allowed in the "if" 

```

block  
include /etc/nginx/fastcgi\_params;  
fastcgi\_param SCRIPT\_FILENAME  
$document\_root/index.php;  
fastcgi\_param SCRIPT\_NAME /index.php;  
fastcgi\_param HTTPS on;  
fastcgi\_read\_timeout 240;

```
                    # rewrite a file not found, pass it to the 

```

backend  
if (!-f $request\_filename) {  
fastcgi\_pass backend;  
break;  
}  
}

```
    }[/i]

```

Thank you for any help  
Luca

Posted at Nginx Forum:

> **[Nginx SSL conf to access phpMyAdmin](https://forum.nginx.org/read.php?2,83832,83832#msg-83832)**
>
> Hi, I have some trouble to configure correctly the access to phpMyAdmin via SSL. 1. problem: when i call the URL https://mydomain.com/phpmyadmin/ I don't have access. 2. problem: If I call the URL https://mydomain.com/phpmyadmin/index.php, I see the...

---

<div class="post-metadata">

**Author:** ![ideanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/71e660/32.png) [@ideanet](https://www.ruby-forum.com/u/ideanet)\
**Post date:** [May 7, 2010, 6:02pm UTC](https://www.ruby-forum.com/t/nginx-ssl-conf-to-access-phpmyadmin/188202/2 "2010-05-07T18:02:07Z")

</div>

On Fri, May 7, 2010 at 8:30 PM, ideanet [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I read that is needed the conf “fastcgi\_param HTTPS on;”, that I have included on my SSL section, but doesn’t have any effect…  
> Â Â Â Â Â Â Â Â ssl\_certificate Â Â Â Â /etc/nginx/mydomain.crt;  
> Â Â Â Â Â Â Â Â location ~ (^/(app/|includes/|lib/|/pkginfo/|var/|report/config.xml)|/.svn/|/.hta.+) {  
> Â Â Â Â Â Â Â Â Â Â Â Â break;  
> Â Â Â Â Â Â Â Â Â Â Â Â include /etc/nginx/fastcgi\_params;  
> Â Â Â Â Â Â Â Â Â Â Â Â # set expire headers
> 
> Â Â Â Â Â Â Â Â Â Â Â Â # rewrite a file not found, pass it to the backend  
> Â Â Â Â Â Â Â Â Â Â Â Â if (!-f $request\_filename) {  
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â fastcgi\_pass backend;  
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â break;  
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â }  
> Â Â Â Â Â Â Â Â }
> 
> Â Â Â Â }[/i]

I’m so confused on where to start. Is that config only for running  
phpmyadmin?

Here’s my phpmyadmin config:

server {  
listen 443 ssl;  
server\_name [myserver.com](http://myserver.com);  
ssl\_certificate /srv/conf/cert/myserver.pem;  
ssl\_certificate\_key /srv/conf/cert/myserver.key;  
location ~ ^/phpmyadmin/.\*.php$ {  
root /srv/http/php;  
fastcgi\_params HTTPS on;  
fastcgi\_pass 127.0.0.1:9100;  
fastcgi\_index index.php;  
fastcgi\_param SCRIPT\_FILENAME $request\_filename;  
include fastcgi\_params;  
}  
location = /phpmyadmin {  
rewrite ^ $scheme://$host$uri/?$args permanent;  
}  
location /phpamyadmin/ {  
index index.php;  
root /srv/http/php;  
expires max;  
}  
}

---

<div class="post-metadata">

**Author:** ![ideanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/71e660/32.png) [@ideanet](https://www.ruby-forum.com/u/ideanet)\
**Post date:** [May 7, 2010, 11:00pm UTC](https://www.ruby-forum.com/t/nginx-ssl-conf-to-access-phpmyadmin/188202/3 "2010-05-07T23:00:04Z")

</div>

On Fri, May 07, 2010 at 09:30:18AM -0400, ideanet wrote:

> I read that is needed the conf “fastcgi\_param HTTPS on;”, that I have included on my SSL section, but doesn’t have any effect…  
> ssl\_certificate /etc/nginx/mydomain.crt;  
> location ~ (^/(app/|includes/|lib/|/pkginfo/|var/|report/config.xml)|/.svn/|/.hta.+) {  
> break;  
> include /etc/nginx/fastcgi\_params;  
> # set expire headers
> 
> Luca  
> Try to simplify configuration and to make it more scaleable:

```
 fastcgi_read_timeout 240;

 location ~ 

```

(^/(app/|includes/|lib/|pkginfo/|var/|report/config.xml)|/.svn/|/.hta.+)  
{  
deny all;  
}

```
 location ~ (\.php|/downloader/?|/report/?)$ {
     try_files /system/maintenance.html $uri =404;

     fastcgi_pass backend;
     include /etc/nginx/fastcgi_params;
     fastcgi_param SCRIPT_FILENAME 

```

$document\_root$fastcgi\_script\_name;  
fastcgi\_param HTTPS on;  
}

```
 location = /downloader { rewrite ^ /downloader/ permanent; }

 location = /downloader/ {
     try_files /system/maintenance.html $uri/ =404;

     fastcgi_pass backend;
     include /etc/nginx/fastcgi_params;
     fastcgi_param SCRIPT_FILENAME 

```

$document\_root/downloader/index.php;  
fastcgi\_param HTTPS on;  
}

```
 location = /report { rewrite ^ /report/ permanent; }

 location = /report/ {
     try_files /system/maintenance.html $uri/ =404;

     fastcgi_pass backend;
     include /etc/nginx/fastcgi_params;
     fastcgi_param SCRIPT_FILENAME $document_root/report/index.php;
     fastcgi_param HTTPS on;
 }

 location ~* "\.(ico|css|js|gif|jpe?g|png)$") {
     try_files $uri @magento;
     expires max;
 }

 location / {
     try_files $uri $uri/ @magento;
     index index.php;
     expires max;
 }

 location @magento {
     fastcgi_pass backend;
     include /etc/nginx/fastcgi_params;
     fastcgi_param SCRIPT_FILENAME $document_root/index.php
     fastcgi_param HTTPS on;
 }

 location = /phpmyadmin { rewrite ^ /phpmyadmin/ permanent; }

```

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![ideanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/71e660/32.png) [@ideanet](https://www.ruby-forum.com/u/ideanet)\
**Post date:** [May 8, 2010, 2:05am UTC](https://www.ruby-forum.com/t/nginx-ssl-conf-to-access-phpmyadmin/188202/4 "2010-05-08T02:05:36Z")

</div>

thank you Igor!  
just another question: it’s possible to define an “allow hosts list” (IP  
or range of IP) for the phpmyadmin directory ?

Posted at Nginx Forum:

> **[Re: Nginx SSL conf to access phpMyAdmin](https://forum.nginx.org/read.php?2,83832,84030#msg-84030)**
>
> Hi, I have some trouble to configure correctly the access to phpMyAdmin via SSL. 1. problem: when i call the URL https://mydomain.com/phpmyadmin/ I don't have access. 2. problem: If I call the URL https://mydomain.com/phpmyadmin/index.php, I see the...

---

<div class="post-metadata">

**Author:** ![ideanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/71e660/32.png) [@ideanet](https://www.ruby-forum.com/u/ideanet)\
**Post date:** [May 7, 2010, 11:13pm UTC](https://www.ruby-forum.com/t/nginx-ssl-conf-to-access-phpmyadmin/188202/5 "2010-05-07T23:13:32Z")

</div>

On Fri, May 07, 2010 at 11:00:50PM +0700, Edho P Arief wrote:

> server {  
> listen 443 ssl;  
> server\_name [myserver.com](http://myserver.com);

> location = /phpmyadmin {  
> rewrite ^ $scheme://$host$uri/?$args permanent;  
> }

You may use just:

```
location = /phpmyadmin { rewrite ^ /phpmyadmin/ permanent; }

```

nginx should add https, server name, and query string.

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![ideanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/71e660/32.png) [@ideanet](https://www.ruby-forum.com/u/ideanet)\
**Post date:** [May 8, 2010, 1:17pm UTC](https://www.ruby-forum.com/t/nginx-ssl-conf-to-access-phpmyadmin/188202/6 "2010-05-08T13:17:30Z")

</div>

On Fri, May 07, 2010 at 08:04:38PM -0400, ideanet wrote:

> thank you Igor!  
> just another question: it’s possible to define an “allow hosts list” (IP or range of IP) for the phpmyadmin directory ?

```
 location ~ ^/phpmyadmin/.+\.php$ {
     try_files /system/maintenance.html $uri =404;

     allow 192.168.1.0/24;
     allow 192.168.3.0/24;
     deny all;

     fastcgi_pass backend;
     include /etc/nginx/fastcgi_params;
     fastcgi_param SCRIPT_FILENAME 

```

$document\_root$fastcgi\_script\_name;  
fastcgi\_param HTTPS on;  
}

```
 location ~ \.php$ {
     ...

```

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![ideanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/71e660/32.png) [@ideanet](https://www.ruby-forum.com/u/ideanet)\
**Post date:** [May 8, 2010, 9:08pm UTC](https://www.ruby-forum.com/t/nginx-ssl-conf-to-access-phpmyadmin/188202/7 "2010-05-08T21:08:01Z")

</div>

thanks Igor!

now I beginning to understand how it works…

Posted at Nginx Forum:

> **[Re: Nginx SSL conf to access phpMyAdmin](https://forum.nginx.org/read.php?2,83832,84259#msg-84259)**
>
> Hi, I have some trouble to configure correctly the access to phpMyAdmin via SSL. 1. problem: when i call the URL https://mydomain.com/phpmyadmin/ I don't have access. 2. problem: If I call the URL https://mydomain.com/phpmyadmin/index.php, I see the...

---

<div class="post-metadata">

**Author:** ![ideanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/71e660/32.png) [@ideanet](https://www.ruby-forum.com/u/ideanet)\
**Post date:** [May 8, 2010, 9:16pm UTC](https://www.ruby-forum.com/t/nginx-ssl-conf-to-access-phpmyadmin/188202/8 "2010-05-08T21:16:13Z")

</div>

On Sat, May 08, 2010 at 03:06:58PM -0400, ideanet wrote:

> thanks Igor!
> 
> now I beginning to understand how it works…

Read also this:

> **[How nginx processes a request](http://nginx.org/en/docs/http/request_processing.html#simple_php_site_configuration)**
>
> nginx first decides which server should process the request. Let’s start with a simple configuration where all three virtual servers listen on port \*:80:

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![ideanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/71e660/32.png) [@ideanet](https://www.ruby-forum.com/u/ideanet)\
**Post date:** [May 8, 2010, 1:15pm UTC](https://www.ruby-forum.com/t/nginx-ssl-conf-to-access-phpmyadmin/188202/9 "2010-05-08T13:15:45Z")

</div>

On Sat, May 08, 2010 at 12:59:02AM +0400, Igor S. wrote:

> > At this point, if I press the back button of the browser and reload the login page, I can enter on the phpMyAdmin.
> > 
> > ```
> > if (-f $document_root/system/maintenance.html) {
> > 
> > ## Magento specific configuration
> > fastcgi_param HTTPS on;
> > 
> > ```
> 
> ```
> location ~ (\.php|/downloader/?|/report/?)$ {
> 
> ```

- 

```
 location ~ (\.php|/downloader/?|/report/?)$ {

```

- 

```
 location ~ \.php$ {

```

> ```
> location = /downloader/ {
> location = /report/ {
> expires max;
> include /etc/nginx/fastcgi_params;
> 
> ```
> 
> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://nginx.org/mailman/listinfo/nginx)

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**
