HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (http://www.howtoforge.com/forums/index.php)
-   Installation/Configuration (http://www.howtoforge.com/forums/forumdisplay.php?f=4)
-   -   Nginx config to see "virtual" files. (http://www.howtoforge.com/forums/showthread.php?t=58343)

talkingnews 22nd August 2012 13:09

Nginx config to see "virtual" files.
 
PyroCMS is a CMS built on top of Codeigniter, and I'm using a module called Pyrostreams. But the reason I'm posting here is because this is actually about nginx config as Apache works fine.

Everything about the entire setup works fine on nginx, except it appears to be trying to call a couple of files from a "virtual" directory, which doesn't exist.

Here's the log entry:

"GET /streams_core/field_asset/css/datetime/datepicker.css HTTP/1.1" 404

The file actually exists in

/www/cms/system/cms/modules/streams_core/field_types/datetime/css

The author says it works just fine in Apache, and isn't able to install nginx himself.

However, here's what he replied with:

Quote:

Looks like it is trying to access the URL as an actual file. The files technically doesn't exist in that location, so it may have a problem with that.

The assets are actually loaded via PHP - there is a field_asset controller under the streams_core module that takes the file name in the URL and outputs it.

It's strange that there would be a compete 404 since it should map anything in index.php/streams_core/field_asset to a function. If you go to index.php/streams_core/field_asset, do you get a blank page?
And yes, I do get a blank page, rather than a 404, so I suppose that shows it's hitting the controller OK?

Here's the nginx config that Pyrocms suggest:
http://docs.pyrocms.com/2.1/manual/i...x-with-php-fpm

Here's the complete nginx config file I'm using:
https://gist.github.com/3419706

And here's the .htaccess file that comes with the application (for those using Apache)
https://gist.github.com/3419710




Been round in a few circles trying to figure this out - a bit lost now. Any ideas would be appreciated.

falko 23rd August 2012 09:44

First, you should escape the dots in the location directives because otherwise they are not treated as dots, bit as placeholders for a character. So

Code:

        location ~* .(?:ico|css|js|gif|jpe?g|png)$ {
                expires max;
                add_header Pragma public;
                add_header Cache-Control "public, must-revalidate, proxy-revalidate";
        }

        location ~ .php {
                fastcgi_pass unix:/var/lib/php5-fpm/web8.sock;
                fastcgi_split_path_info ^(.+.php)(.*)$;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;

fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;

fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;

fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors off;
        }

should be

Code:

        location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
                expires max;
                add_header Pragma public;
                add_header Cache-Control "public, must-revalidate, proxy-revalidate";
        }

        location ~ \.php {
                fastcgi_pass unix:/var/lib/php5-fpm/web8.sock;
                fastcgi_split_path_info ^(.+.php)(.*)$;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;

fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;

fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;

fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors off;
        }

Second, the author says that the css request should be passed to the PHP interpreter which doesn't happen because this location matches:

Code:

        location ~* .(?:ico|css|js|gif|jpe?g|png)$ {
                expires max;
                add_header Pragma public;
                add_header Cache-Control "public, must-revalidate, proxy-revalidate";
        }

I therefore suggest you comment out that location and reload nginx.

talkingnews 23rd August 2012 10:47

Quote:

Originally Posted by falko (Post 284084)
First, you should escape the dots in the location... Second, the author says that the css request should be passed to the PHP interpreter which doesn't happen because this location matches...

Falko, once again you have solved a problem that many others couldn't.

Thank you! My only concern now would be how I would make that js and css that was served via the interpretor compressible and cache-able - not sure I can? But at least the form is working properly now!

Worth every penny of the subscription (which I had running for ages but only cancelled last month when I changed PP account... so I was giving a little back for a while - will have to resub!)

falko 25th August 2012 09:25

Quote:

Originally Posted by talkingnews (Post 284102)
Thank you! My only concern now would be how I would make that js and css that was served via the interpretor compressible and cache-able - not sure I can? But at least the form is working properly now!

I think you have to do this by PHP (that is, your application has to do). Maybe it can compress and/or minify the files and also set the correct cache headers.


All times are GMT +2. The time now is 14:36.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.