Nginx Configuration and 404 Error

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Nginx Configuration and 404 Error

sah62
I'm getting an HTTP 404 error when I delete a message from my Trash folder.
I'm hoping that someone can help me identify a fix.

I have a message from my Trash folder displayed. The hyperlink to delete the
message uses this URL:

https://mydomain.net/squirrelmail/src/delete_message.php?mailbox=INBOX.Trash
&message=71&smtoken=kIZ3gr8ct9Jn&sort=6&startMessage=1

Clicking on "Delete" produces a 404. This is what I see in my web server
log:

X.X.X.X - - [26/Jan/2016:08:17:26 -0500] "GET
/squirrelmail/src/delete_message.php/squirrelmail/src/right_main.php?sort=6&
startMessage=1&mailbox=INBOX.Trash HTTP/1.1" 404 206
"https://mydomain.net/squirrelmail/src/read_body.php?mailbox=INBOX.Trash&pas
sed_id=71&startMessage=1" "Mozilla/5.0 (Windows NT 10.0; WOW64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36"

Note the path associated with the GET -
/squirrelmail/src/delete_message.php/squirrelmail/src/right_main.php. That
path is invalid (and the source for the 404), but what's causing that path
to be sent to the web server? I get the same 404s when I move a message from
one folder to another, delete a message from my Inbox, etc.

Here's some diagnostic information. First, configtest output:

SquirrelMail version: 1.4.23 [SVN]
Config file version: 1.4.0
Config file last modified: 01 April 2013 19:16:01
Checking PHP configuration...
    PHP version 5.5.9-1ubuntu4.14 OK.
    Running as www-data(33) / www-data(33)
    display_errors:
    error_reporting: 22527
    variables_order OK: GPCS.
    PHP extensions OK. Dynamic loading is disabled.
    ERROR: You have configured PHP not to allow short tags
(short_open_tag=off). This shouldn't be a problem with SquirrelMail or any
plugin coded coded according to the SquirrelMail Coding Guidelines, but if
you experience problems with PHP code being displayed in some of the pages
and changing setting to "on" solves the problem, please file a bug report
against the failing plugin. The correct contact information is most likely
to be found in the plugin documentation.

Checking paths...
    Data dir OK.
    Attachment dir OK.
    Plugins OK.
    Themes OK.
    Default language OK.
    Base URL detected as:
https://mydomain.net/squirrelmail/src/configtest.php/squirrelmail/src
(location base autodetected)
Checking outgoing mail service....
    SMTP server OK (220 mydomain.net ESMTP Postfix (Ubuntu))
Checking IMAP service....
    IMAP server ready (* OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR
LOGIN-REFERRALS ID ENABLE IDLE STARTTLS AUTH=PLAIN AUTH=LOGIN AUTH=CRAM-MD5]
Dovecot (Ubuntu) ready.)
    Capabilities: * CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID
ENABLE IDLE STARTTLS AUTH=PLAIN AUTH=LOGIN AUTH=CRAM-MD5
Checking internationalization (i18n) settings...
     gettext - Gettext functions are available. On some systems you must
have appropriate system locales compiled.
     mbstring - Mbstring functions are available.
     recode - Recode functions are unavailable.
     iconv - Iconv functions are available.
     timezone - Webmail users can change their time zone settings.
Checking database functions...
    not using database functionality.
Congratulations, your SquirrelMail setup looks fine to me!

OS version: Ubuntu 14.04.3 LTS (GNU/Linux 4.1.5-x86_64-linode61 x86_64)

PHP version: PHP 5.5.9-1ubuntu4.14 (cli) (built: Oct 28 2015 01:32:13)

nginx version: nginx/1.4.6 (Ubuntu)

Here's my nginx config:

        location /squirrelmail {
                root /usr/share/;
                index index.php index.html index.htm;
                location ~ ^/squirrelmail/(.+\.php)$ {
                        try_files $uri =404;
                        root /usr/share/;
                        include /etc/nginx/fastcgi_params;
                        fastcgi_pass unix:/var/run/php5-fpm.sock;
                        fastcgi_param HTTPS on;
                        fastcgi_index index.php;
                        fastcgi_buffer_size 128k;
                        fastcgi_buffers 256 4k;
                        fastcgi_busy_buffers_size 256k;
                        fastcgi_temp_file_write_size 256k;
                }
                location ~*
^/squirrelmail/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
                        root /usr/share/;
                }
        }
        location /webmail {
                rewrite ^/* /squirrelmail last;
        }

Thanks for your help,
Scott


------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
-----
squirrelmail-users mailing list
Posting guidelines: http://squirrelmail.org/postingguidelines
List address: [hidden email]
List archives: http://news.gmane.org/gmane.mail.squirrelmail.user
List info (subscribe/unsubscribe/change options): https://lists.sourceforge.net/lists/listinfo/squirrelmail-users
Reply | Threaded
Open this post in threaded view
|

Re: Nginx Configuration and 404 Error

sah62
I think I see the problem:

> Base URL detected as:
> https://mydomain.net/squirrelmail/src/configtest.php/squirrelmail/src
> (location base autodetected)

The base URL is incorrect. What would cause this to be autodetected incorrectly?

Scott
Reply | Threaded
Open this post in threaded view
|

Re: Nginx Configuration and 404 Error

sah62
More info: I've discovered an issue with the value returned from the $_SERVER['PHP_SELF'] variable. For some reason the value contains the path to a particular file concatendated to itself, like this:

/squirrelmail/src/left_main.php/squirrelmail/src/left_main.php

This causes HTTP 404 errors when attempting to process (delete, move, etc) displayed messages because the path to the PHP source files ends up being invalid. The fix is to replace PHP_SELF with SCRIPT_NAME in the functions/strings.php file at line 1514 inside the php_self() function.That is, change this:

if (!sqgetGlobalVar('PHP_SELF', $request_uri, SQ_SERVER)

to this:

if (!sqgetGlobalVar('SCRIPT_NAME', $request_uri, SQ_SERVER)

I entered a bug report in SourceForge (https://sourceforge.net/p/squirrelmail/bugs/2829/) that was closed as invalid with this comment:

"While the various CGI variables provided by PHP can seem like a web of confusion, they are never given in such incorrect fashion unless you have a botched server-side configuration. This problem is not a SquirrelMail problem; it is a mistake in your Nginx/FCGI configuration."

So back to my original question: can someone please help me figure out what's broken in my Nginx/FCGI configuration? It's working just fine for other services I'm running on the same server, like Drupal.
Reply | Threaded
Open this post in threaded view
|

Re: Nginx Configuration and 404 Error

Paul Lesniewski
On 1/27/16, sah62 <[hidden email]> wrote:

> More info: I've discovered an issue with the value returned from the
> $_SERVER['PHP_SELF'] variable. For some reason the value contains the path
> to a particular file concatendated to itself, like this:
>
> /squirrelmail/src/left_main.php/squirrelmail/src/left_main.php
>
> This causes HTTP 404 errors when attempting to process (delete, move, etc)
> displayed messages because the path to the PHP source files ends up being
> invalid. The fix is to replace PHP_SELF with SCRIPT_NAME in the
> functions/strings.php file at line 1514 inside the php_self() function.That
> is, change this:
>
> if (!sqgetGlobalVar('PHP_SELF', $request_uri, SQ_SERVER)
>
> to this:
>
> if (!sqgetGlobalVar('SCRIPT_NAME', $request_uri, SQ_SERVER)
>
> I entered a bug report in SourceForge
> (https://sourceforge.net/p/squirrelmail/bugs/2829/) that was closed as
> invalid with this comment:
>
> "While the various CGI variables provided by PHP can seem like a web of
> confusion, they are never given in such incorrect fashion unless you have a
> botched server-side configuration. This problem is not a SquirrelMail
> problem; it is a mistake in your Nginx/FCGI configuration."
>
> So back to my original question: can someone please help me figure out
> what's broken in my Nginx/FCGI configuration? It's working just fine for
> other services I'm running on the same server, like Drupal.

Make sure you literally looked at the contents of $_SERVER['PHP_SELF']
and not some SquirrelMail interpretation thereof such as $PHP_SELF.
If the former does in fact include that duplicate path, you need to
review your Nginx configuration.  Asking for help in the Nginx mailing
list might be more appropriate in that case.

--
Paul Lesniewski
SquirrelMail Team
Please support Open Source Software by donating to SquirrelMail!
http://squirrelmail.org/donate_paul_lesniewski.php

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
-----
squirrelmail-users mailing list
Posting guidelines: http://squirrelmail.org/postingguidelines
List address: [hidden email]
List archives: http://news.gmane.org/gmane.mail.squirrelmail.user
List info (subscribe/unsubscribe/change options): https://lists.sourceforge.net/lists/listinfo/squirrelmail-users
Reply | Threaded
Open this post in threaded view
|

Re: Nginx Configuration and 404 Error

sah62
In reply to this post by sah62
OK, problem solved. There are a great number of nginx configuration guides that suggest this configuration setting if you're using FastCGI:

fastcgi_param PATH_INFO $fastcgi_script_name;

Commenting out this setting fixed the problem for me. I'd like to thank Paul Lesniewski for pointing me in the right direction.