Username
Forgot password?
Welcome to our site!
Or Join with FTTF

Lampcms on NGINX

0

2200 views
Was playing around with nginx and made lampcms work, pretty easy too.
These are just some quick and dirty solutions - I will have to find more ideal rewrite rules, but for now:
made nginx run on port 8088
pointed dev.lampcms.com to the same server as this site.
accessing dev.lampcms.com:8088 goes to NGINX and then points to the same exact php code as in support.lampcms.com

The reason I even started experimenting with nginx is because I want to setup lampcms on Amazon AWS and will be using nginx there for sure.

I think it will be really cool to run a Lampcms on AWS on small instance, I am thinking maybe setup mongodb on small or medium instance and actual web server can be on the free micro instance.

Here are the simple config file for NGINX, pay attention to the TODO1 and TODO2 comments - if you know the solution please post - I am not the NGINX expert, can use some help.


(saved this file in /etc/nginx/conf.d/dev.lampcms.conf)
restarted nginx and it worked
Here it goes:

server {
listen 8088;
server_name dev.lampcms.com;
access_log /var/log/nginx/log/host.access.log main;

root /usr/local/sites/support.lampcms.com/www;

# If site is accessed without any dir or file just by www.site.org
# then default to index.php
location / {
index index.php;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

#
# TODO1: need to reproduce these lighttpd rules:
#
#"/_assets/*" => "$0",
# ".*\.(png|gif|jpg|jpeg|css|js|ico)$" => "$0",
# ".*\.(css|js)\?t" => "$0",
# "/api/api.php*" => "$0"
#
# MAYBE TRY SOMETHING LIKE THIS:
#
#
# if ($request_uri !~ ^/(index\.php|assets|files|robots\.txt)) {
# rewrite ^/(.*)$ /index.php/$1 last;
#}
#
# OR this one - skips rules for matching location?
# location ~* ^/(assets|files|robots\.txt) { }
# Try to put this one BELOW the other master rule


#
# TODO2: need to reproduce these expire rules:
#
# expire.url = (
# "/images/" => "access plus 10 years",
# "/js/min/" => "access plus 10 years",
# "/style/" => "access plus 1 days",
# )
#
#
# This rewrite rule is the key to pointing all requests to index.php
# This probably bad solution because nginx will check if file
# exists on every request
# this is just a quick and dirty solution and should be replaced
# with something better - look at TODO1 above!
if (!-e $request_filename)
{
rewrite ^/(.*)$ /index.php?/$1 last;
break;
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
# No need to setup root directive here!
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
 
asked February 3, 2014 at 6:18 PM

 us

2 Answers

0
 
test test test
flag
answered March 14, 2015 at 5:30 PM
0
 
Here is a much improved version of nginx config file. It has all the necessary directive to add long cache headers for css, minified js and images
Also has direction for output compression (gzip) and the rewriting all requests to index.php is very simple now
I tested on this sites' nginx server and it works well.

Here it is:
###############
server {
listen 8088;
server_name dev.lampcms.com;
access_log /var/log/nginx/log/host.access.log main;

gzip on;
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain application/xml;

root /usr/local/sites/support.lampcms.com/www;

# If site is accessed without any dir or file just by www.site.org
# then default to index.php
# This is exact match, no furter matches will be done for requests to /
location = / {
index index.php;
}

# Exact match for /api/api.php
# In this case do not try any more rules
location = /api/api.php {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

#
# These dirs will have max Cache time
#

location ^~ /images/ {
expires max;
}

location ^~ /js/min/ {
expires max;
}

location ^~ /style/ {
expires max;
}


# For security deny access to .ini files
# Lampcms own .ini files are outside web dir anyway, but this is just
# in case someone wants to keep their !config.ini inside the www directory
location ~ \.ini$ {
deny all;
}
# Forward everything to front controller
# If actual file or dir does not exist
location / {
try_files $uri $uri/ /index.php;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}


# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
# No need to setup root directive here!
location ~ \.php$ {
# For security reason disallow ../ tricks
location ~ \..*/.*\.php$ {return 404;}
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;

# If fastcgi php is on the same server as nginx then fastcgi_index is not needed
#if fastcgi server is remote one, and nginx has no access to its
#filesystem, then index has no idea about remote index files. The fastcgi_index
#should help here: it simply adds its value to any /dir/, i.e. it maps
#/dir/ to /dir/index.php.

fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}

}
flag
answered February 5, 2014 at 6:39 PM

Your answer

Join with account you already have

FTTF

Preview

Alert