Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mehany's avatar
Level 13

In Ajax: any configuration difference between Nginx and Apache

I moved a Laravel 4.2 application from my development server which runs on nginx (no SSL) to a shared hosting server which runs on Apache ( with SSL ).

[ edited ] The problem : The site's JS scripts ( multiple JQuery Ajax functions ) was fully tested and worked as intended while the application was on the nginx server. Once migrated to the production server which run on Apache, Ajax function with "POST" method stopped working!

My .htaccess file looks like this:

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

and filters.php has:

App::before(function($request)
{
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Origin, Content-Type, Accept, Authorization, X-Request-With');
header('Access-Control-Allow-Credentials: true');

if( ! Request::secure() )
{
    return Redirect::secure( Request::path() );
}
});

Here is an example Headers from production

Remote Address:ipAddress:443
Request URL:https://example.com/store/
Request Method:POST
Status Code:301 Moved Permanently

The same exact request on development

Remote Address:ipAddress:80
Request URL:http://example.com/store/
Request Method:POST
Status Code:200 OK

A little hint to confirm if the above configuration has nothing to do with the problem or where to investigate, is greatly appreciated!

Thanks

[Edited 5-27-2015] rephrased some wording

0 likes
8 replies
sitesense's avatar
Level 19

I shouldn't think it would make a difference.

Open up developer tools in Chrome and switch to the network tab.

Here you can see what is happening with your Ajax requests. Check the correct urls are being used.

1 like
bashy's avatar

And the problem is..?

This means nothing in the developer world

work as intended on the nginx server but not on Apache for some reason.

mehany's avatar
Level 13

@sitesense that is what i do, yeb. I added headers example above! @bashy right! hope now make a little more sense.

bashy's avatar

I see the perm move one but what's the new URL?

bashy's avatar

Nope, you need to supply the Location: value

Example

┌[Ben☮Titan]-(~)
└> curl -I http://laracasts.com
HTTP/1.1 301 Moved Permanently
Server: nginx/1.6.0
Date: Thu, 28 May 2015 11:00:29 GMT
Content-Type: text/html
Content-Length: 184
Connection: keep-alive
Location: https://laracasts.com/
mehany's avatar
Level 13

@bashy here you go

Connection:Keep-Alive
Content-Length:234
Content-Type:text/html; charset=iso-8859-1
Date:Thu, 28 May 2015 02:33:00 GMT
Keep-Alive:timeout=5
Location:https://example.com/store
Server:Apache/2.4.12 (Unix) OpenSSL/1.0.1e-fips mod_bwlimited/1.4 mod_fcgid/2.3.10-dev
mehany's avatar
Level 13

I am able to make POST requests to the same production server from a cordova app. The above issue is happening only when I post from a browser! here is my Ajax

;(function(){

$('.create-store').click(function(){
    $.ajax({
          type : 'POST',
          url: "/store/", // I also tried url : "https://www.example.com/store/" 
          data: $('form').serialize(),
          beforeSend: function( xhr ) {
              // add authorization token
          },
          error: function(data){
              // handle error   
          },
          success : function(data){
              // handle success message
          }
        })
          .done(function( data ) {
            //alert('updated'); 
        }); 
    });
})();

Please or to participate in this conversation.