How do I install ViMP under NGINX?

Editions: Light, Ultimate, Corporate
Versions: 4.3.0+

Starting with version 4.3.0 you can also run ViMP under NGINX. Just install NGINX with PHP-FPM on your server. In the following we assume that NGINX is already running and PHP files can be delivered.

Then create a new NGINX server configuration under /etc/nginx/sites-enabled (e.g. vimp.conf) or alternatively edit your existing default configuration. 

The NGINX configuration for ViMP must look like this (replace the root directory and the server name and log directories according to your server configuration):

server {
  rewrite_log off;
 
  listen 80;
  listen [::]:80 ipv6only=on;

  # replace /var/www/vimp/ with your actual ViMP installation folder path in the following line
  root /var/www/vimp/web;

  # replace your_servername with your actual server name in the following line
  server_name your_servername;

  # replace /var/www/vimp/ with your actual ViMP installation folder path in the following lines
  access_log /var/www/logs/vimp_nginx_access.log;
  error_log /var/www/logs/vimp_nginx_error.log warn;

  index index.php frontend.php webtv.php backend.php frontend_dev.php webtv_dev.php backend_dev.php index.html;

  charset utf-8;
  server_tokens off;

  client_max_body_size 500M;

  # Disable access log for favicon.ico
  location = /favicon.ico {
    log_not_found off;
    access_log off;
  }

  # Disable access log for robots.txt
  location = /robots.txt {
    allow all;
    log_not_found off;
    access_log off;
  }

  # Prevent access to files/folders which starts with a dot
  location ~ /\. {
    deny all;
    access_log off;
    log_not_found off;
  }

  # Directive for dynamic JS files which are processed by PHP
  location ~ ^/(.+)\.js\.php(/|$) {
    error_page 417 = @appwebtv;
    error_page 418 = @appfrontend;
    error_page 419 = @appbackend;
    if ( $query_string ~ "app=webtv" ) { return 417; }
    if ( $query_string ~ "app=frontend" ) { return 418; }
    if ( $query_string ~ "app=backend" ) { return 419; }
  }

  # Directive for dynamic JS files which are processed by PHP
  location @appfrontend {
    index index.php;
    #include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    #fastcgi_pass 127.0.0.1:9000;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param HTTPS off;
    try_files $uri $uri/ /index.php;
  }

  # Directive for dynamic JS files which are processed by PHP
  location @appwebtv {
    index webtv.php;
    #include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    #fastcgi_pass 127.0.0.1:9000;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param HTTPS on;
    try_files $uri $uri/ /webtv.php;
  }

  # Directive for dynamic JS files which are processed by PHP
  location @appbackend {
    index backend.php;
    #include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    #fastcgi_pass 127.0.0.1:9000;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param HTTPS off;
    try_files $uri $uri/ /backend.php;
  }

  # All front controllers for symfony
  location ~ ^/(index|frontend_dev|frontend_cache|backend|backend_dev|backend_cache|getMedia|health|webtv|webtv_dev|webtv_cache)\.php(/|$) {
    #include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    #fastcgi_pass 127.0.0.1:9000;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param HTTPS off;
  }

  # Try to serve file directly, fallback to rewrite to default frontend controller
  location / {
    index index.php;
    try_files $uri $uri/ @rewriteapp;
  }

  # Rewrite fallback to index.php
  location @rewriteapp {
    rewrite ^(.*)$ /index.php$1 last;
  }
}

Note: Be sure to set fastcgi_param HTTPS to "on" when you're running your website under https!

 

Last update on 2021/02/22 by Admin.

Go back