Report this

What is the reason for this report?

How to use phpBB, phpMyAdmin with Unicorn and nginx?

Posted on October 30, 2014

I used the 1-Click Ruby on Rails on Ubuntu 14.04 Image and this guide to setup my rails app: https://www.digitalocean.com/community/tutorials/how-to-use-the-1-click-ruby-on-rails-on-ubuntu-14-04-image . Then, I used the the PHP guide https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-12-04 to install PHP.

On my previous shared host, I ran the phpBB forum from inside the rials public directory. The Apache .htaccess file had an entry to turn off the rails rewrite rule.

How can I achieve this with nginx? Right now when I go to www.mydomain.com/forum , rails returns a 404 error. How can I tell nginx to server php inside my /home/myrailsapp/public/forum ? Is there a better way? Below is my nginx config file.

server {
        listen   80;
        root /home/myrailsapp/public;
        server_name my_ip;
        index index.htm index.html index.php;

        location / {
                try_files $uri/index.html $uri.html $uri @app;
        }

        location ~* ^.+\.(jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|mp3|flv|mpeg|avi)$ {
                        try_files $uri @app;
        }

        location @app {
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                proxy_redirect off;
                proxy_pass http://app_server;
        }
        # pass the PHP scripts to FastCGI server listening on the php-fpm socket
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
}


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

You’ll want to set up a location directive for the forum that will not direct requests to the proxy pass. It would look something like:

        location /forum {
            root /path/to/phpmybb;
            index index.php index.html index.htm;
            try_files $uri $uri/ =404;
        }

Let us know how it goes!

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.