0

i’ve tried several configuration instructions and forum posts but nothing worked for me, I still get 502-bad gateway errors when I try to access my website.

$config[“index_page”] = “”;

...

$config[“uri_protocol”] = “REQUEST_URI”; // also tried AUTO

My nginx configuration:

server {
    server_name     dev.monitr.io;
    root            /home/monitr/web/dev/www/;
    include         /etc/sites/ci_vhost;
} 

/etc/sites/ci_vhost:

index index.html index.php index.htm;

# 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/ @rewrites;
}

location @rewrites {
        if (!-e $request_filename)
        {
            rewrite ^/(.*)$ /index.php/$1 last;
            break;
        }
    }

   location ~ \.php {
        include /etc/nginx/fastcgi_params;

        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param SCRIPT_NAME $fastcgi_script_name;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass unix:/var/run/php-fastcgi/php-fastcgi.socket;
        fastcgi_index index.php;
} 

kind regards, phillip

14
  • Check that your fastcgi is running: sudo ps ax | grep php and check existanceof /var/run/php-fastcgi/php-fastcgi.socket Commented Nov 19, 2011 at 14:51
  • php-fpm is running but the socket doesnt exist. replaced it with fastcgi_pass 127.0.0.1:9000; and now the gateway works, but i get 500-server error messages (dev.monitr.io) Commented Nov 19, 2011 at 14:58
  • When php fatal error happens fastcgi send 500 header to nginx. You can temporary replace your framework with single phpinfo script and check out your installation. Commented Nov 19, 2011 at 15:25
  • dev.monitr.io - here you can see the configuration Commented Nov 19, 2011 at 15:34
  • 1
    You don't have php5_mysql package installed. 99% sites on CI use mysql. Think, your's also. On debian do something like apt-get install php5-mysql. If 500 apperas again set in php.ini display_erros to true and error reporting to E_ALL. You should see php error and understand the problem. If not, set in php.ini error_log = /absolute/path/to/logfile and read it. Btw, look in /var/log/php-fpm.log (or smth like this). If there is no log for php-fpm, set it in /etc/php5/php-fpm.ini (or smth like this). Good luck! Commented Nov 19, 2011 at 15:44

1 Answer 1

1

Follow instruction to add dotdeb.org to you apt sources. Dotdeb.org has packages of modern nginx and php.

  1. apt-get update
  2. apt-get install nginx
  3. configure nginx (your previous config is more or less ok, google "nginx php 5.3" manuals)
  4. apt-get install php5-cli php5-common php5-suhosin //suhosin is good for security
  5. apt-get install php5-fpm php5-cgi
  6. /etc/init.d/nginx restart
  7. /etc/init.d/php5-fpm restart
  8. Try your phpinfo script
  9. Install mysql, pear, etc. Don't forget about some opcode cacher - huge perfomance boost for CI.

Google "nginx php 5.3" for complete manuals, there are many. Wish you not to compile anything from sources :)

Sign up to request clarification or add additional context in comments.

3 Comments

one little question: when I want to protect that domain with a htpasswd file, I put: auth_basic "Restricted"; auth_basic_user_file /etc/nginx/htpasswd; into the location ~ \.php{} but nothing happens
Do you add location / { auth_basic "Restricted"; auth_basic_user_file htpasswd; } to you /etc/nginx/nginx.config (or smth), like in docs wiki.nginx.org/HttpAuthBasicModule
Never used this module, sorry. All I can suggest is this link from official wiki: kbeezie.com/view/protecting-folders-with-nginx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.