Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

This is our config file, we're having problems with the front-end functionality of the app that does work on Apache.

Javascript POST method is not working anymore.

server {

    listen   80;
    server_name website.com www.website.com;
    rewrite ^/(.*) https://website.com/$1 permanent;
}

server {

    listen   443;
    server_name website.com www.website.com;


    ssl    on;
    ssl_certificate    /etc/ssl/www_website_com.pem;
    ssl_certificate_key    /etc/ssl/website.com.key;

    ssl_session_timeout 5m;

    root        /usr/share/nginx/www.website.com;
    index index.html index.php;

    # canonicalize codeigniter url end points
    # if your default controller is something other than "welcome" you should change the following
    if ($request_uri ~* ^(/home(/index)?|/index(.php)?)/?$)
    {
            rewrite ^(.*)$ / permanent;
    }

    # removes trailing "index" from all controllers
    if ($request_uri ~* index/?$)
    {
            rewrite ^/(.*)/index/?$ /$1 permanent;
    }

    # removes trailing slashes (prevents SEO duplicate content issues)
    if (!-d $request_filename)
    {
            rewrite ^/(.+)/$ /$1 permanent;
    }

    # removes access to "system" folder, also allows a "System.php" controller
    if ($request_uri ~* ^/system)
    {
            rewrite ^/(.*)$ /index.php?/$1 last;
            break;
    }

    # unless the request is for a valid file (image, js, css, etc.), send to bootstrap
    if (!-e $request_filename)
    {
            rewrite ^/(.*)$ /index.php?/$1 last;
          break;
    }

    # catch all
    error_page 404 /index.php;

    # set expiration of assets to MAX for caching
    location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
            expires max;
            log_not_found off;
    }

    location / {
            # Check if a file exists, or route it to index.php.
            try_files $uri $uri/ /index.php;
            auth_basic            "Restricted";
            auth_basic_user_file  /etc/nginx/htpasswd;
    }

    location ~* \.php$ {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_connect_timeout 60;
            fastcgi_send_timeout 180;
            fastcgi_read_timeout 180;
            fastcgi_buffers 512 32k;
            fastcgi_buffer_size 64k;
            include fastcgi_params;

    # PHP only, required if PHP was built with --enable-force-cgi-redirect
            fastcgi_param   REDIRECT_STATUS         200;
            fastcgi_param SCRIPT_FILENAME /usr/share/nginx/www.website.com$fastcgi_script_name;
    }

    location ~ /\.ht
{
    deny all;
  }

  }

Answer:

I finally know what went wrong and how to fix it. The config of nginx should only apply to static JS, not to the PHP actions.

Configure this:

location ~ ^/(assets)/ {
  expires max;
  break;
 }

Replace "assets" with "js" and it will work.

share|improve this question
    
Please move your 'answer' section to an actual answer. –  Scott Pack Nov 19 '11 at 13:44

2 Answers 2

Your (permanent) rewrite rule will return a 301 redirect for every request - including POSTs. So any post vars will be lost

share|improve this answer
    
Thank you so much, can you please give me an example how I fix this problem? –  Ernst Nov 14 '11 at 17:25
    
I have fixed the problem with your help. Thank you very much. Everybody who is having this problem, do not rewrite in your config :) –  Ernst Nov 15 '11 at 8:48
    
@Ernst: good news - it might help others to know how you fixed it? –  symcbean Nov 15 '11 at 9:13
    
yes, but actually it's for some strange reason bugged again. That's why I haven't posted the result. I will add the config again. I've added the edited config as per your comment. –  Ernst Nov 15 '11 at 12:26
    
updated my question with the answer. –  Ernst Nov 16 '11 at 12:41
up vote 1 down vote accepted

Answer:

I finally know what went wrong and how to fix it. The config of nginx should only apply to static JS, not to the PHP actions.

Configure this:

location ~ ^/(assets)/ {
 expires max;
 break;
}

Replace "assets" with "js" and it will work.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.