I have a websiteA which is working juste fine. When going to websiteA/backend, a sub location is used within nginx to serve another website.

With my config, a blank page is returned when going to websiteA/backend and the js & css are returned as html.

Can you please help me ? Thanks.

My virtualhost:

 ### Use to not log the route53 health checks in the logs
map $http_user_agent $log_ua {
        "ELB-HealthChecker/2.0" 0;
        default 1;

server {
        server_name websiteA www.websiteA;
        root /var/www/websiteA/;
        index index.php index.html;
        access_log /var/log/nginx/websiteA.access.log combined if=$log_ua;
        error_log /var/log/nginx/websiteA.com.error.log;

        # Return a 404 not found for every hidden files
        location ~ /\. {
                deny all;
                return 404;

        # set expiration of assets to MAX for caching
        location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
                expires max;
                log_not_found off;

        location / {
                # Check if a file or directory index file exists, else route it to index.php.
                try_files $uri  /index.html;

        location ~ ^/backend/ {
                alias /var/www/backend/;
                try_files $uri $uri/ /index.php?$args;
                location ~* \.php$ {
                        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
                        fastcgi_split_path_info ^(.+\.php)(/.+)$;
                        fastcgi_param PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin;
                        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
                        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                        fastcgi_index index.php;
                        fastcgi_param CI_ENV test;
                        fastcgi_param DOMAIN test;
                        include fastcgi.conf;

        location ~ /(_sql|_templates|application|changelogs|docs|uploads|CHANGELOG.md|CSVTranslator.js|JSONUpdater.js|README.md|bower.json|composer.json|composer.lock|g_i18n_extractor.js|gulpfile.js|package-lock.json|package.json|robots.txt)
                 deny all;
                 return 404;


Thanks for your help.

  • Why have you made the location a regex match? – Michael Hampton May 7 at 17:16
  • You should probably be using location ^~ /backend { root /var/www; ... } instead of the regular expression and the alias directive. – Richard Smith May 8 at 8:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.