Skip to main content

SuiteCRM API V8 không chạy trên Nginx

SuiteCRM API V8 không chạy trên Nginx

Vấn đề: Khi lấy access token từ REST API v8  của SuiteCRM sẽ gặp lỗi 404 trên Nginx

Nguyên nhân là do file .htaccess không hiệu quả trên server Nginx nên cần thêm config dành riêng cho Nginx để cho REST API V8 có thể chạy được trên Nginx

     location ~ /Api/ {
        index   index.php;
        try_files $uri @rewrite_api;

        location ~ .php {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        }
    }

    location @rewrite_api {
        rewrite ^/Api/(.*)?$    /Api/index.php/$1       last;
    }

Có thể xem tham khảo config đầy đủ bên dưới


 server {
     listen 80;
     server_name suitecrm.example.com;
 
     # Automatically redirect to HTTPS
     return 301 https://$host$request_uri;
 }
 
 # Nginx SSL for SuiteCRM
 server {
 
     server_name suitecrm.example.com;
 
     # Enable http2
     listen 443 http2 ssl;
 
     # SSL Config
     ssl_certificate /etc/letsencrypt/live/suitecrm.example.com/fullchain.pem;
     ssl_certificate_key /etc/letsencrypt/live/suitecrm.example.com/privkey.pem;
     ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
     ssl_ciphers HIGH:!aNULL:!MD5;
 
     client_max_body_size 50M;
 
     index index.php index.html index.htm;
     root /opt/suitecrm;
 
     location / {
         root /opt/suitecrm;
         index index.php index.html index.htm;
     }
  
     error_page 500 502 503 504 /50x.html;
     error_log /var/log/nginx/suitecrm.irsyadf.me.error.log;
 
     location = /50x.html {
         root /var/www/html;
     }
 
     ## Images and static content is treated different
     location ~* ^.+\.(jpg|jpeg|gif|css|png|js|ico|xml|svg|wgoff2)$ {
         access_log off;
         expires max;
         root /opt/suitecrm;
     }
 
     location ~ \.php$ {
         try_files $uri =404;
         fastcgi_pass unix:/run/php/php7.0-fpm.sock;
         fastcgi_index index.php;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
         include fastcgi_params;
     }
 
     location ~ /\.ht {
         deny all;
     }

     ## config for REST API V8
     location ~ /Api/ {
        index   index.php;
        try_files $uri @rewrite_api;

        location ~ .php {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        }
    }

    location @rewrite_api {
        rewrite ^/Api/(.*)?$    /Api/index.php/$1       last;
    }
 
 }