Search code examples
phpapachesymfonynginxorocrm

OROCRM Nginx Virtual Host Configuration Not Working


I have installed a orocrm on a AWS Lightsail VPS with Nginx & PHP7. orocrm installed without a hitch but I'm using Nginx for the first time and my virtual host doesn't seem to be working.

sites-available/default: server { listen 80 default_server; listen [::]:80 default_server;

        root /var/www/html;
        index app.php index.php index.html;
        server_name 34.127.224.10;

        location / {
                try_files $uri $uri/ =404;
        }

        location ~ \.php$ {
                fastcgi_pass   unix:/run/php/php7.0-fpm.sock;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
                include        fastcgi_params;
        }

        location ~ /\.ht {
                deny all;
        }
}

I then purchased & pointed crmdomain.com to my instance and created another file.

sites-available/crm:

server {
        listen 80;
        server_name crmdomain.com www.crmdomain.com;
        root /var/www/html/crm/web;

        index app.php;

        error_log /var/log/nginx/orocrm_error.log;
        access_log /var/log/nginx/orocrm_access.log;

        location = /favicon.ico { access_log off; log_not_found off; }
        location = /robots.txt  { access_log off; log_not_found off; }

        location @rewrite { rewrite ^/(.*)$ /app.php/$1; }

        location / {
                try_files $uri /app.php$is_args$args;
        }

        location ~ [^/]\.php(/|$) {
                fastcgi_split_path_info ^(.+?\.php)(/.*)$;
                if (!-f $document_root$fastcgi_script_name) {
                        return 404;
                }
                fastcgi_index app.php;
                fastcgi_read_timeout 10m;
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
}

I honestly don't know most of what is above, it's mostly based on tutorial and apache experience.

Errors

Domain based

 - crmdomain.com -> 403 Forbidden nginx/1.10.0 (Ubuntu)
 - crmdomain.com/app.php -> No input file specified.
 - crmdomain.com/app_dev.php -> No input file specified.
 - crmdomain.com/index.nginx-debian.html -> Welcome to nginx!
 - crmdomain.com/user/login -> 404 Not Found nginx/1.10.0 (Ubuntu) **This is what should word**

Static IP based

 - 34.127.224.10 -> 403 Forbidden nginx/1.10.0 (Ubuntu)
 - 34.127.224.10/crm/web/ - No input file specified.
 - 34.127.224.10/crm/web/app.php - No input file specified.
 - 34.127.224.10/crm/web/app_dev.php - No input file specified.
 - 34.127.224.10/index.nginx-debian.html -> Welcome to nginx!
 - 34.127.224.10/crm/web/app.php/user/login -> 404 Not Found nginx/1.10.0 (Ubuntu) **This is what should word**

What am I doing wrong?


Solution

  • It's weird how often I answer my own questions:

    I was able to change the default files and remove the extra virtual host. Since the server was only going to host the one app.

    server {
            listen 80 default_server;
            listen [::]:80 default_server;
    
            server_name 34.127.224.10 crmdomain.com www.crmdomain.com;
            root /var/www/html/crm/web;
            index app.php app_dev.php index.php;
    
            location / {
                    # try to serve file directly, fallback to app.php
                    try_files $uri /app.php$is_args$args;
            }
    
        location ~ ^/(app|app_dev|config|install)\.php(/|$) {
                #fastcgi_pass 127.0.0.1:9000;
                # or
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
                fastcgi_split_path_info ^(.+\.php)(/.*)$;
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_param HTTPS off;
        }
    
            error_log /var/log/nginx/orocrm_error.log;
            access_log /var/log/nginx/orocrm_access.log;
    }