Welcome! Log In Create A New Profile

Advanced

SugarCRM / SuiteCRM wiki example outdated, and rewrites question

Posted by talkingnews 
SugarCRM / SuiteCRM wiki example outdated, and rewrites question
January 04, 2016 09:55AM
In https://www.nginx.com/resources/wiki/start/ there's a link to an example for SugarCRM which leads to https://www.howtoforge.com/running-sugarcrm-community-edition-on-nginx-lemp-on-debian-squeeze-ubuntu-11.04.

However, that config won't work on the current version of Sugar/Suite CRM (SuiteCRM is a fork of SugarCRM so the base code is the same)

At the foot of that howtoforge page is a note that an up to date config can be found at http://www.dontesta.it/blog/en/blog-2/crm/configure-nginx-sugarcrm/, however, it contains a lot of rewrites and IFs. Although we know that "if is evil" and sometimes can't be avoided, this doesn't look like "the nginx way" of doing things.

Can anyone find a "sexier" more nginx way of doing this config? Thanks!

(can also be found at https://suitecrm.com/forum/developer-help/4102-suitecrm-nginx-config with some extra fascgi_cache stuff).

Example config pasted below, although the forum often messes this part up...

location / {
if (!-d $request_filename){
set $rule_0 true;
}
if (!-f $request_filename){
set $rule_0 true;
}
if ($rule_0){
rewrite ^/rest/(.*)$ /api/rest.php?__sugar_url=$1 last;
rewrite ^/cache/api/metadata/lang_(.._..)_(.*)_public.json$ /rest/v10/lang/public/$1?platform=$2 last;
rewrite ^/cache/api/metadata/lang_(.._..)_([^_]*).json$ /rest/v10/lang/$1?platform=$2 last;
rewrite ^/portal/(.*)$ /portal2/$1 last;
rewrite ^/portal$ /portal/? permanent;
}

try_files $uri $uri/ index.php;
}
Re: SugarCRM / SuiteCRM wiki example outdated, and rewrites question
January 04, 2016 10:09AM
That example is exactly how not to use IF, and what is the point of all those rewrites?

What first needs to be done is to answer what needs to be tested and what is expected for the application to work.

Start with a basic stripped down config and use the logs/debug logs to figure out why things are not working, then we can think about solving that. For 99% of these kind of applications it is best to start from zero instead of mixing all kinds of 'solutions' which are basically the wrong type of Apache conversions.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: SugarCRM / SuiteCRM wiki example outdated, and rewrites question
January 04, 2016 10:14AM
Additionally, when you start from zero and things don't work do NOT try to be smart and add all kinds of things to make it work because that will only bring you back to square one. If it doesn't work STOP and ask for assistance, once you and the forum users understand whats going on, solutions are not too far away.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: SugarCRM / SuiteCRM wiki example outdated, and rewrites question
January 04, 2016 10:24AM
Thanks - yes, these configs have nothing to do with me. They are merely the ones found by following the nginx wiki and also the SuiteCRM forum.

According to the page I linked to (http://www.dontesta.it/blog/en/blog-2/crm/configure-nginx-sugarcrm/) the rewrites are there because a REST API in SuiteCRM. The page gives a link to the original Apache .htaccess which are below.

As you say, it doesn't look good, so I am doing what you suggest and asking for assistance :)

I am not smart enough with nginx to be able to fully know the intricacies of the config files, so I was hoping for some ideas at the same time as pointing out that the wiki link was out of date.

Here's the .htaccess which comes with the application.

Options +FollowSymLinks
RewriteEngine On
# Replace with the relative web root path to your instance
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^rest/(.*)$ api/rest.php?__sugar_url=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^cache/api/metadata/lang_(.._..)_(.*)_public.json$ api/rest.php/v10/lang/public/$1?platform=$2 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^cache/api/metadata/lang_(.._..)_([^_]*).json$ api/rest.php/v10/lang/$1?platform=$2 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^cache/Expressions/functions_cache(_debug)?.js$ api/rest.php/v10/ExpressionEngine/functions?debug=$1 [L,QSA]
Re: SugarCRM / SuiteCRM wiki example outdated, and rewrites question
January 04, 2016 11:07AM
Start with something simple:

worker_processes 2;

events {
worker_connections 16384;
}

http {
include mime.types;
default_type application/octet-stream;
sendfile off;
server_names_hash_bucket_size 128;
map_hash_bucket_size 64;
tcp_nodelay on;

#
server {
listen 80;
server_name bla.nl;
root 'bla';
location / {
try_files $uri $uri/ =404;
index index.html index.htm index.php;
}
location ~ \.php$ {
try_files $uri $uri/ =404;
index index.php;
fastcgi_ignore_client_abort on;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}

Adjust it for your needs and check logfiles for errors, keep it simple.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: SugarCRM / SuiteCRM wiki example outdated, and rewrites question
January 04, 2016 12:40PM
Thanks - out on mobile and will try in morning - but that looks like a very default config - how will it "know" to do those rewrites?

Anyway, I'll see what happens, debug and report back when stuck! Thanks again.
Re: SugarCRM / SuiteCRM wiki example outdated, and rewrites question
January 04, 2016 02:20PM
Just start with the basics, you might not need any rewrite at all and if you do we first need to see whats happening before figuring out what to do about it.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: SugarCRM / SuiteCRM wiki example outdated, and rewrites question
January 04, 2016 05:54PM
OK.... mind... blown!

It seems to work. I've tried lots of different things in the admin, and it all just... works.

Just with those few lines you gave me.

But... how does it know??

This is nginx magic at its best!

Just one more question:

I found someone else had a go at an nginx config: https://gist.github.com/bnaydenov/413956374c3123bc354b - as you can see, again, it is massive, and I wonder if I should be incorporating some of the restrictions in the .htaccess file below?

Meantime, thank you again. There are so many "bad" nginx config files out there, it's a minefield.

# BEGIN SUGARCRM RESTRICTIONS
RedirectMatch 403 .*\.log$
RedirectMatch 403 /+not_imported_.*\.txt
RedirectMatch 403 /+(soap|cache|xtemplate|data|examples|include|log4php|metadata|modules)/+.*\.(php|tpl)
RedirectMatch 403 /+emailmandelivery\.php
RedirectMatch 403 /+upload
RedirectMatch 403 /+custom/+blowfish
RedirectMatch 403 /+cache/+diagnostic
RedirectMatch 403 /+files\.md5$
# END SUGARCRM RESTRICTIONS
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^cache/jsLanguage/(.._..).js$ index.php?entryPoint=jslang&module=app_strings&lang=$1 [L,QSA]
RewriteRule ^cache/jsLanguage/(\w*)/(.._..).js$ index.php?entryPoint=jslang&module=$1&lang=$2 [L,QSA]
</IfModule>
Re: SugarCRM / SuiteCRM wiki example outdated, and rewrites question
January 04, 2016 06:59PM
I know its a minefield, thats why I said what I said, its not that complicated, people are making it complicated :)

For each Apache redirect you really have to ask yourself what it is suppose to do, ALWAYS refer to debug logging to find out why something isn't working.

And (repeating myself) if you want to know why thing work look into the debug logging because it will tell you exactly what its doing.

---
nginx for Windows http://nginx-win.ecsds.eu/
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 145
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready