Not serving static files - Nginx Wordpress Jails

Hi All,

I am updating a server and also trying to work with jail.

The problem I am trying to solve is the static files. I can see several 404 for js and css files on chrome console. The files exist and I tried to install previous versions of php72 and wordpress 5.0 still same issue.

No Css/Js on wordpress pages frontend. The backend has few css styles but they do not come from js or css files.


I am following this tutorial about Multiple Jails https://www.freebsd.org/doc/en/books/handbook/jails-application.html

The server is an ec2 instance. I have separate jails for:
  1. Php73 and Wordpress 5.1
  2. Nginx 1.14
  3. MySql Server 80
I do not have any messages on nginx-error.log (nginx/error.log) or php-fpm.log

Checked the Wordpress permissions files/dir and also owner:group (www)

Here is my Nginx.conf today

Code:
user  www;
worker_processes  1;

error_log  /var/log/nginx-error.log;

events {
    worker_connections  2000;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    upstream php {
                  server     [2600:1f1e:cb6:7700:6aeb:df8f:e1ec:d0e3]:9000;
    }

    sendfile        on;

    keepalive_timeout  65;

    server {
        listen       172.30.0.49:80;
        listen       [2600:1f1e:cb6:7700:766c:545d:beab:2547]:80;

        server_name  ec2.ip ;

        root   /usr/local/www;
        index  index.php;

        server_tokens off;

        location / {
            try_files \$uri \$uri/ /index.php?\$args;
        }

        location ~ \.php$ {
               fastcgi_pass   php;
               fastcgi_index  index.php;
               fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
               include        fastcgi_params;
        }
    }

}

How can I serve the wordpress css/js files from WP/Php Jail?

Thanks

Edit: typo.
 
This tutorial is a little bit obsolete. Nowadays there is a separate config file for the jails to keep your rc.conf cleaner.
I had success using this jail tutorial: https://www.cyberciti.biz/faq/how-to-configure-a-freebsd-jail-with-vnet-and-zfs/

It should be quite easy to move your jail settings to jail.conf from your current state.

Also regarding 404 errors: make sure your nginx jail has the files within its root directory. You should not put the files to serve on the main host, but in the jail itself. So if your nginx docu says "/usr/local/www/..." you actually go "/jails/nginxjail/root//usr/local/www..." you get the point. The jail has access only within its root directory.
 
How can I serve the wordpress css/js files from WP/Php Jail?
Ah, you want to serve files from the other jail?
Normally a jail sees only files that are mounted within its root tree.
You could use jail's fstab file (see jail(8)) to mount a directory in read-only mode in a second jail. Or you could do it as if the jails were separate physical hosts - via some kind of file protocol like NFS although I think this would be an overkill.

By the way, why do you want to put PHP and the web server in different jails? Is this not exactly the point of PHP - that it needs to be interpreted in the webserver itself? Unless you explicitly want to isolate them for some reason, I would put PHP in the same jail as the webserver it's running on.
 
This tutorial is a little bit obsolete. Nowadays there is a separate config file for the jails to keep your rc.conf cleaner.
I had success using this jail tutorial: https://www.cyberciti.biz/faq/how-to-configure-a-freebsd-jail-with-vnet-and-zfs/

It should be quite easy to move your jail settings to jail.conf from your current state.

Also regarding 404 errors: make sure your nginx jail has the files within its root directory. You should not put the files to serve on the main host, but in the jail itself. So if your nginx docu says "/usr/local/www/..." you actually go "/jails/nginxjail/root//usr/local/www..." you get the point. The jail has access only within its root directory.

Hi roccobaroccoSC,

Thanks for your reply, yes I try to clear warnings so I need to do a few updates on that tutorial.

I have a jail.conf file. The hostname php bellow I changed to better describe here.

Code:
path = "/usr/home/jail/$name";                          # Path to the jail
host.hostname = "$name";                                # Hostname
allow.raw_sockets;
exec.start = "/bin/sh /etc/rc";                             # Start command
exec.stop = "/bin/sh /etc/rc.shutdown";            # Stop command
exec.clean;
mount.devfs;                                                       # Mount devfs inside the jail
#devfs_ruleset = "www_ruleset";                        # devfs ruleset

php {
    ip6.addr = "2600:1f1e:cb6:7700:6aeb:df8f:e1ec:d0e3";
    ip4.addr = "172.30.0.43";                                # IP address of the jail
}

mysql {
    ip6.addr = "2600:1f1e:cb6:7700:9b3a:de65:cbfd:62b1";
    ip4.addr = "172.30.0.138";                              # IP address of the jail
}

nginx {
    ip6.addr = "2600:1f1e:cb6:7700:766c:545d:beab:2547";
    ip4.addr = "172.30.0.49";            # IP address of the jail
}

Also I need to make distribution DESTDIR when following that tutorial.

I checked your link, I did not use zfs or vnet in these tests.

I tried jail also installing without templates and with ezjail. I could make basic install with them too.


About the 404 error, yes that root /usr/local/www on nginx.conf is from Php Wordpress Jail.

Wordpress is installed in directory, not subdirectory default (/wordpress).

Ah, you want to serve files from the other jail?

Yes I have them in separate jails. One for Nginx and the other Php/wordpress. Also MySql is in another.

Nginx I thought use separate so I could use for other web projects.


Is this not exactly the point of PHP - that it needs to be interpreted in the webserver itself?

So this way will not work? I was thinking of using fastcgi for the php and nginx to serve direct the static files. It seems the php is working.


Thanks
 
You need a way to share the files between the jails.
The easiest way I can think of is to mount them in the nginx jail read-only via nullfs. Use the jail's mount.fstab property and create an fstab file. Mount the directory in the nginx jail via nullfs. Then it will be able to find them.

it should go something like that:
Code:
# jail.conf
nginxjail {
  mount.fstab = "/path/to/fstab-file"  # This is outside the jail root dir
}

# fstab-file for nginx
/usr/home/phpjail/usr/local/www/..../javascript /usr/local/www/..../javascript nullfs ro 0 0

This would mount the javascripts of your phpjail into your nginx jail as readonly.
 
You need a way to share the files between the jails.
The easiest way I can think of is to mount them in the nginx jail read-only via nullfs. Use the jail's mount.fstab property and create an fstab file. Mount the directory in the nginx jail via nullfs. Then it will be able to find them.

it should go something like that:
Code:
# jail.conf
nginxjail {
  mount.fstab = "/path/to/fstab-file"  # This is outside the jail root dir
}

# fstab-file for nginx
/usr/home/phpjail/usr/local/www/..../javascript /usr/local/www/..../javascript nullfs ro 0 0

This would mount the javascripts of your phpjail into your nginx jail as readonly.

I thought I could do it with nat/pf and nginx.

I am going to try the jail fstab but seems like the template/skel to jail (multiple jails tutorial).

Thanks
 
Back
Top