Nginx Configuration Example
petermoo opened this issue · comments
I could not find an Nginx configuration example so I used the following.
server {
listen 80;
server_name mecha.local;
access_log /home/example/web/mecha/access-logs/access.log;
error_log /home/example/web/mecha/access-logs/error.log;
root /home/peter/example/mecha/public_html;
index index.php;
location / {
try_files $uri $uri/ @rewrite;
}
# Include PHP 7 config.
include /home/example/web/nginx.php7.conf;
location @rewrite {
rewrite ^/(.*)$ /index.php?_=$1? last;
}
}
You may need to include the query string as well?
/index.php?_=$1&$args
Adding the two subdirectory excludes. Removed ? from rewrite to automatically append the query.
server {
listen 80;
server_name mecha.local;
access_log /home/example/web/mecha/access-logs/access.log;
error_log /home/example/web/mecha/access-logs/error.log;
root /home/peter/example/mecha/public_html;
index index.php;
location ^~ /engine {
deny all;
return 404;
}
location ^~ /lot {
deny all;
return 404;
}
location / {
try_files $uri $uri/ @rewrite;
}
# Include PHP 7 config.
include /home/example/web/nginx.php7.conf;
location @rewrite {
rewrite ^/(.*)$ /index.php?_=$1 last;
}
}
What will happen with the .\lot\asset
, .\lot\layout\asset
and .\lot\x\*\lot\asset
folder then? They must be accessible in public.
I found the CSS problem and added two allows for it. The lot/x/*/lot/asset problem is an estimate as I did not find a test for it.
server {
listen 80;
server_name mecha.local;
access_log /home/example/web/mecha/access-logs/access.log;
error_log /home/example/web/mecha/access-logs/error.log;
root /home/example/web/mecha/public_html;
index index.php;
location ^~ /engine {
deny all;
return 404;
}
# The following allow has to be before lot deny.
location ~ /lot/x/.*/lot/asset/ { allow all; }
location ^~ /lot {
deny all;
return 404;
}
location ^~ /lot/asset { allow all; }
location ^~ /lot/layout/asset { allow all; }
location / { try_files $uri $uri/ @rewrite; }
# Include PHP 7 config.
include /home/example/web/nginx.php7.conf;
location @rewrite {
rewrite ^/(.*)$ /index.php?_=$1 last;
}
}
I am no longer working on a Mecha test site. The test site had no added extensions to test assets in subfolders of x. Any future requirements will have to be worked out by someone else.
This gist should become the final result. I will try to keep it up-to-date.