CONFIGURE NGINX FOR PHP SYMFONY PROJECT ON CENTOS 7

Assuming having a virtual site called api

sudo vi /etc/nginx/conf.d/api.conf

point root to the web folder

server {

        listen 80;
        listen [::]:80;
        server_name www.yoursite.com;
        root /usr/share/nginx/html/api/web;

        access_log /var/log/nginx/access.log;
        error_log  /var/log/nginx/error.log error;

        #site root is redirected to the app boot script
        location = / {
                try_files $uri @rewriteapp;
        }

        location @rewriteapp {
                # rewrite all to app.php
                rewrite ^(.*)$ /app.php/$1 last;
        }

        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;
        location /50x.html {
                root /usr/share/nginx/html/api/web;
        }

         # Deny all . files
        location ~ /\. {
                deny all;
        }

        location ~ ^/(app|app_dev|config)\.php(/|$) {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
                fastcgi_index index.php;
                include /etc/nginx/fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }
}

Let’s test it

http://www.yoursite.com

YEEYYYY!!!!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s