­
+1 (408) 320-0380

Nginx server configuration for EspoCRM on Ubuntu server

This post may not be actual at this moment. Please follow to the article in the documentation.

These instructions are supplementary to the Server Configuration guideline. Please note that all configuration settings listed here are made on Ubuntu server.

PHP requirements

To install all necessary libraries, run these commands in a terminal:

1
2
3
4
sudo apt-get update
sudo apt-get install php-mysql php-json php-gd php-mcrypt php-zip php-imap php-mbstring php-curl
sudo phpenmod mcrypt imap mbstring
sudo service nginx restart

Fixing the issue “API Error: EspoCRM API is unavailable”:

Take only necessary steps. After each step check if the issue is solved.

1. Enable rewrite rules in Nginx server

Add this code to your Nginx server block config file (/etc/nginx/sites-available/YOUR_SITE) inside “server” block:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
server {  
    # ...
     
    client_max_body_size 50M;
 
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
 
    location /api/v1/ {
        if (!-e $request_filename){
            rewrite ^/api/v1/(.*)$ /api/v1/index.php last; break;
        }
    }
 
    location /portal/ {
        try_files $uri $uri/ /portal/index.php?$query_string;
    }
 
    location /api/v1/portal-access {
        if (!-e $request_filename){
            rewrite ^/api/v1/(.*)$ /api/v1/portal-access/index.php last; break;
        }
    }
 
    location ~ /reset/?$ {
        try_files /reset.html =404;
    }
 
    location ^~ (data|api)/ {
        if (-e $request_filename){
            return 403;
        }
    }
    location ^~ /data/logs/ {
        deny all;
    }
    location ^~ /data/\.backup/ {
        deny all;
    }
    location ^~ /data/config.php {
        deny all;
    }
    location ^~ /data/cache/ {
        deny all;
    }
    location ^~ /data/upload/ {
        deny all;
    }
    location ^~ /application/ {
        deny all;
    }
    location ^~ /custom/ {
        deny all;
    }
    location ^~ /vendor/ {
        deny all;
    }
    location ~ /\.ht {
        deny all;
    }
}

If you don’t have this file, you have to create it. For this open a terminal and run a command:

1
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/espocrm.conf

And add the code listed above. For more information on how to configure a new Virtual Host on Nginx, please read this guideline.

Run this command in a terminal to check if everything is fine:

1
sudo nginx -t

If so, run the command to restart nginx server:

1
sudo service nginx restart

2. Add RewriteBase path

Open a file /ESPOCRM_DIRECTORY/api/v1/.htaccess and replace the following line:

1
# RewriteBase /

with

1
RewriteBase /REQUEST_URI/api/v1/

where REQUEST_URI is a part of URL, e.g. for “http://example.com/espocrm/”, REQUEST_URI is “espocrm”.

Cookies & Privacy Policy

Our website uses cookies to give you the best user experience on our website and to help us deliver our services. By using our services, you agree to our use of cookies. Click here for more information.
Necessary
Strictly necessary cookies help make a website navigable by activating basic functions such as page navigation and access to secure website areas. Without these cookies, the website would not be able to work properly.
Statistical
Statistical cookies help the website owner understand how visitors interact with the website by collecting and reporting information.
Marketing
Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and interesting to the individual user and thus more valuable for publishers and third-party advertisers.
Accept AllCustomizeAccept Necessary