wcms
wcms copied to clipboard
Nginx seems fine?
In the README it states that it is a requirement to use Apache to use W. My partner just installed W served with nginx on our home-server. All seems fine until now. Is there a reason, that I don't see, why it should be a requirement? Otherwise I can create a PR for updating this with some nginx conf on the side.
Cheers for your work, W is great!
Hey thanks for the feedback ! 😃
I just never tested W with Nginx. I fought that .htaccess file was only working with Apache, so that's why it was indicated as "Apache only".
After a few search on the net, it really looks like this should not work as the .htaccess file logic is not implemented in Nginx.
This blog post explains that it's a design choice meant to avoid performance issues.
Maybe you're Nginx config is using this kind of plugin: https://github.com/e404/htaccess-for-nginx ??
Or maybe you are using PHP dev Webserver ?
Hi, thanks for the response! I prefer using nginx over apache. The .htaccess is "just" overriding apache configuration, and none of the configuration in .htaccess seems that special that it can not be translated to nginx configuration. It is true that the .htaccess file is redundant when using nginx.
The configuration in the .htaccess file:
# and 'assets' and 'media' folder
DirectorySlash off
RewriteEngine on
# everything that does not contain asssets|media
RewriteCond %{REQUEST_URI} !^(.*)/(assets|media)/ [OR]
# or that isn't a file
RewriteCond %{REQUEST_FILENAME} !-f
# is redirect to index
RewriteRule . index.php [L]
Can be translated to the following in nginx configuration, that has to be placed within the server block in nginx:
# no directory listing
autoindex off;
# serve static files directly
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
try_files $uri =404;
}
# handle assets and media directories
location ~* ^/(assets|media)/ {
try_files $uri =404;
}
The following is not neeeded, because it is a not a problem in nginx:
CGIPassAuth On
I think it would be good to update the readme so users with nginx web servers can be included? I can make a PR if you agree.
Cheers ❤️
Ok ! I got it now !! 😋
I think it would be good to update the readme so users with nginx web servers can be included? I can make a PR if you agree.
That would be lovely !
Ideally I would like to test it myself before merging, but I do not have a dedicated local Nginx setup.
-> Or maybe @n-peugnet we could try it quickly on club1 server ?
Then we could discuss about it here, or in a dedicated PR.
@vincent-peugnet @n-peugnet Sounds good. Let me know if you need any assistance in testing this, and when you feel comfortable for me starting a PR for the README. I can confirm it works well with nginx for over a month now with consistent usage of wcms on our end.
I just tried to serve W behind nginx too!
I came up with this configuration inside the server block:
# Max upload size
# This must be set as well in PHP-FPM's conf
# /etc/php/8.2/fpm/php.ini
# upload_max_filesize = 50M
# post_max_size = 50M
client_max_body_size 50m;
# All files in assets and media folders are served directly by NGINX
location ~ ^/(assets|media)/ {
# root is put here as extra security:
# we don't want NGINX to serve anything else in this folder
root /var/www/html;
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# Everything else is handled by index.php
location / {
rewrite ^ /index.php last;
}
# index.php redirects to PHP-FPM
location = /index.php {
# root is put here as extra security:
# we don't want NGINX to serve anything else in this folder
root /var/www/html;
include snippets/fastcgi-php.conf;
# With php-fpm (or other unix sockets):
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
# With php-cgi (or other tcp sockets):
#fastcgi_pass 127.0.0.1:9000;
}
I'm curious how W could work without the rewrite directive @adionditsak!
Is there some part of the conf missing in you previous comment?
I'm curious how W could work without the
rewritedirective
IIRC, an option could be to use something like try_files /index.php?$query_string; instead of the rewrite directive in your location / {} block.
But it is kind of the same thing 😁
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
@adionditsak : I'm a bit worried by this line in your config, because it seems to limit what kind of file should be uploaded in W's media. I don't think this should be the case.
The config we got working with @ppom0 don't have this limitation.
If you have the time, could you tell us if you see any issue with this one ?
You are right that it should be a less restrictive file serving for a more general config file to recommend users.
@ppom0 looks good to me. I would ensure that directory listing are not possible, in case there is files that is uploaded, but you not necessarily want to expose.
Hey ! I opened a PR to add this in the README.
@ppom0 looks good to me. I would ensure that directory listing are not possible, in case there is files that is uploaded, but you not necessarily want to expose.
Thanks for the suggestion ! I added a line about that in ppom's config !