We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Phalcon + Nginx + Windows

Hello again. I want to switch from Apache to Nginx because according to what I've read Nginx is more powerful (if its not true please tell me). But my problem is with the configuration (Im running WINDOWS desktop). For example if I want to try the INVO app it loads the plain html but no css and stuff and other controllers don't work as well (so when I click on About nothing changes but url). My nginx config is https://gist.github.com/Honzaik/9351610 and if I use the other one featured on the phalcon nginx install page this one https://gist.github.com/Honzaik/9351665 it doesnt work either. the root page should be set correctly because the 1st page loads (without css etc.). I've been googling this for 2 days and nothing worked for me, I would really appreciate your help and explanation if possible. As well what configuration should I use, if the "Using $_GET[‘_url’] as source of URIs" or "Using $_SERVER[‘REQUEST_URI’] as source of URIs" and why. Thank you very much

edited Mar '14

here is my nginx setup for INVO.

// invo.dev config
    server {

        listen    80;
        server_name invo.dev;

        index index.php index.html index.htm;
        set $root_path '/usr/local/var/www/invo/public';

        root $root_path;

        try_files $uri $uri/ @rewrite;

        location @rewrite {
            rewrite ^/(.*)$ /index.php?_url=/$1;
        }

        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9001;
            fastcgi_index  index.php;
            fastcgi_param SCRIPT_FILENAME $request_filename;
            fastcgi_param REQUEST_URI $uri?$args;
            include        fastcgi_params;
        }

        location ~*^/(css|img|js|flv|swf|download)/(.+)$ {
            root $root_path;
        }

        location ~ /\.ht {
            deny all;
        }
    }

change root path, servername and fastcgi pass to your need and add: 127.0.0.1 invo.dev - to your hosts file.

This works for me on my Mac, CentOS and Ubundu server.



9.4k

thank for a response but sadly it doesnt work for me. the page loads as before but still without any css etc. when i go to localhost/invo/css/style.css it redirects me the index.php file again. i've tried to set it up on ec2 with nginx + php-fpm-5.5 but it just looks like this https://54.194.244.235/ can you tell me please what am I doing wrong? this is the dir with info files https://i.imgur.com/ifTH9x3.png and I have root directory in nginx set to /var/www/phalcon/public thats correct right? btw this rewrite log might be useful https://gist.github.com/Honzaik/9356698



58.4k

@Honzaik Can you give file nginx config?



940
Accepted
answer
edited Mar '14

in app/config/config.ini you have to change line number 13:

baseUri = /invo/ to: baseUri = /



58.4k
edited Mar '14

Hi When click menu "Contact" on https://54.194.244.235/ -> https://54.194.244.235/invo/contact/index It mean cache or

    set $root_path '/usr/local/var/www/invo/public'; incorrect

You try empty file in volt folder



9.4k
edited Mar '14

thank you it's working now. I thought of that baseUri change but I thought it should work anyway. so that means everytime I want it to work from root folder I have to change the baseUri to / correct? this is the nginx conf file https://gist.github.com/Honzaik/9369815



58.4k
edited Mar '14

base application URL (not needed if you use virtual hosts) apache2, if nginx serve block see https://www.digitalocean.com/community/articles/how-to-set-up-nginx-virtual-hosts-server-blocks-on-ubuntu-12-04-lts--3



9.4k
edited Mar '14

thanks, I'll definitely look into that!



15.1k

IIS ftw :D



4.5k
edited Mar '14

This is my config. Keep in mind that a try_files directive, if used right might be a bit better than a rewrite, not to mention a try_files directive using a rewrite


server {
  listen                192.168.56.144:80;

  server_name           phalcon.es www.phalcon.es;
  root /var/www/phalcon.es/public;
    index  index.php index.html index.htm;

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

  location / {
    root  /var/www/phalcon.es/public;
    try_files $request_uri $request_uri/ /index.php$is_args$args;
    index  index.html index.htm index.php;
    gzip on;
  }
  location ~* \.(ico|3gp|gif|jpg|cur|svg|jpeg|png|wmv|avi|asf|asx|mpg|mpeg|mp4|woff|pls|mp3|mid|wav|swf|flv|js|html|htm|txt|css|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso|htc)(\?[0-9]+)?$ {
    access_log off;
    add_header Pragma "public";
    error_log off;
    expires max;
    log_not_found off;
  }

  location ~* \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    try_files $uri =404;
    include /etc/nginx/fastcgi_params;
    fastcgi_pass unix:/var/run/php5-fpm.sock;

    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  }

include /etc/nginx/mime.types;
}
edited Oct '15

I am new to nginx and phalcon. I have configured nginx and php.Currently studying tutorial in phalcon. I am working on windows machines. But i couldn't set up .htacess rules. When i run that tutorial example given in study material on apache it runs fine, but it doesn't run on nginx. Tutorial framework has following directory structure: .htacess public app. Now .htacess has following rules:- RewriteEngine on
RewriteRule ^$ public/ [L] RewriteRule (.*) public/$1 [L]

App folder contains models, views and controllers.Public folder contain assets like js, css and images. Public folder has another .htacess with following rules:- AddDefaultCharset UTF-8 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]

My php is configured and running well, i have also setup a small utility to startup and stop server.Root path that i have provided is:- C:/nginx/html I have tried different location rules for framework to run .. but non e of them seems to be working.Can anyone help me in setup rules.Here is the content of my nginx.conf file:- server { listen 80; server_name localhost; root C:/nginx/html;

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

location /tutorial {
rewrite ^/tutorial/(.*)$ /tutorial/public/$1 break;
try_files $uri $uri/ /tutorial/public/index.php?q=$uri&$args;
}

location ~ \.php/ {
     fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;

    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include        fastcgi_params;
}