Assets not loaded

Viewed 2253

I have problem, my assets not loaded - 404 Not Found

"nelmio/api-doc-bundle": "^3.6@dev"

I executed php bin/console assets:install and php bin/console assets:install --symlink

Locally works, but on the test server don't works... could someone know some magic about this ?

locally Request URL: http://symfony.localhost/bundles/nelmioapidoc/swagger-ui/swagger-ui-bundle.js - loaded correct

On the test server http://11.11.11.11/bundles/nelmioapidoc/swagger-ui/swagger-ui.css not loaded

and returned error

in /var/www/symfony/vendor/friendsofsymfony/rest-bundle/View/ViewHandler.php (line 163)
Format 'html' not supported, handler must be implemented

I checke files in /var/www/symfony/public/bundles, looks like correct, files present in nelmioapidoc. What I missed ?

fos rest configuration:

fos_rest:
    body_listener:
        service: my_body_listener
    unauthorized_challenge: "Basic realm=\"Restricted Area\""
    access_denied_listener:
        # all requests using the 'json' format will return a 403 on an access denied violation
        json: true
    param_fetcher_listener: force
    format_listener:
        rules:
            - { path: ^/api, prefer_extension: true, fallback_format: json, priorities: [ json ] }
            - { path: ^/, priorities: [ json, xml, html ], fallback_format: ~, prefer_extension: true }
    view:
        view_response_listener: 'force'
        formats:
            json: true
            jsonp: false
            xml: false
            rss: false
        mime_types:
            json: ['application/json', 'application/x-json']
    routing_loader:
        default_format:  json
    exception:
        enabled: true
        codes:
            'Symfony\Component\Routing\Exception\ResourceNotFoundException': 404
            'Doctrine\ORM\OptimisticLockException': HTTP_CONFLICT
            'Symfony\Component\HttpKernel\Exception\BadRequestHttpException': 400
        messages:
            Symfony\Component\HttpKernel\Exception\BadRequestHttpException: true
            Symfony\Component\HttpKernel\Exception\HttpException: true

But I guess it not relation with fos rest. Because this is assetic resources, it should be loaded without handling. And for most important thing, locally woks without any problem

Another thing, maybe problem with server. I use Docker with nginx image. This my conf nginx.conf:

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
  worker_connections  2048;
  multi_accept on;
  use epoll;
}

http {
  server_tokens off;
  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;
  keepalive_timeout 15;
  types_hash_max_size 2048;
  include /etc/nginx/mime.types;
  default_type application/octet-stream;
  access_log off;
  error_log off;
  gzip on;
  gzip_disable "msie6";
  include /etc/nginx/conf.d/*.conf;
  include /etc/nginx/sites-enabled/*;
  open_file_cache max=100;
  client_body_temp_path /tmp 1 2;
  client_body_buffer_size 256k;
  client_body_in_file_only off;
}

daemon off;

and host

server {
    server_name symfony.localhost;
    root /var/www/symfony/public;


    location / {
        try_files $uri @rewriteapp;
    }

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

    location ~ ^/index\.php(/|$) {
        fastcgi_pass php-upstream;
        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/symfony_error.log;
    access_log /var/log/nginx/symfony_access.log;
}

statat for file in test server (I add chmod 777 -R vendor/nelmio) when executed assts:install --symlink (the same case when propel value, without --symlink)

/var/www/symfony # stat public/bundles/nelmioapidoc/swagger-ui/swagger-ui.css
  File: public/bundles/nelmioapidoc/swagger-ui/swagger-ui.css
  Size: 154006      Blocks: 304        IO Block: 4096   regular file
Device: fc01h/64513d    Inode: 1038685     Links: 1
Access: (0777/-rwxrwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2020-03-26 08:43:56.025515192 +0000
Modify: 2020-03-25 16:45:47.667069605 +0000
Change: 2020-03-26 08:42:59.921460536 +0000
 Birth: -

For compare example from local (where works correct)

    /var/www/symfony # stat public/bundles/nelmioapidoc/swagger-ui/swagger-ui.css
  File: public/bundles/nelmioapidoc/swagger-ui/swagger-ui.css
  Size: 154006      Blocks: 304        IO Block: 4096   regular file
Device: 805h/2053d  Inode: 5797767     Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2020-03-25 16:12:02.252465289 +0000
Modify: 2020-03-25 16:10:42.100983234 +0000
Change: 2020-03-25 16:10:42.100983234 +0000
 Birth: -
1 Answers

I resolved this problem with a little change in nginx default.conf like:

set $root_path '/var/www/{YOUR_SYMFONY_PROJECT}/public';

root $root_path;

location ~* ^/(bundles)/(.+)$ {
    root $root_path;
}

I hope I have helped you

Related