Nginx config for running WordPress under "my_webapp"

My YunoHost server

Hardware: VPS bought online
YunoHost version: 11.1.15
I have access to my server : Through SSH
Are you in a special context or did you perform some particular tweaking on your YunoHost instance ? : no
If your request is related to an app, specify its name and version: 1.0~ynh13

Description of my issue

Hi guys,

I’m trying to get WordPress to run under my_webapp to easily be able to switch PHP versions. But I get that error where the urls don’t get rewritten for subpages (and only show 404 errors).

I edited the config file located at /etc/nginx/config.d/DOMAIN.d/my_webapp__X.conf but don’t get any results from it. I’ve added try_files $uri $uri/ /index.php?q=$uri&$args; to location / { .. }.

I’ve managed to get it running about half a year ago on some other app but can’t remember what I did lol (and also the config file of that app looks untouched which is weird…) Any ideas? I feel like I’m not editing the right file…


You have to add

 if (!-e $request_filename)
     rewrite ^(.*)$ /index.php?q=$1 last;

this is my file

#sub_path_only rewrite ^/$ / permanent;
location / {

    # Path to source
    alias /var/www/my_webapp/www/;

    # Default indexes and catch-all
    index index.html index.php;
    try_files $uri $uri/ /index.php?$args;
    # Remove index.php from URL _RR
    if (!-e $request_filename)
     rewrite ^(.*)$ /index.php?q=$1 last;
    # increase upload limit size _RR
    client_max_body_size 256M; 
    # Prevent useless logs
    location = /favicon.ico {
        log_not_found off;
        access_log off;
    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;

    # Deny access to hidden files and directories
    location ~ ^/(.+/|)\.(?!well-known\/) {
        deny all;

    # Execute and serve PHP files
    location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        fastcgi_pass unix:/var/run/php/php8.0-fpm-my_webapp.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param REMOTE_USER $remote_user;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $request_filename;

    # Include SSOWAT user panel.
  #  include conf.d/;

1 Like

Yup, this did the trick. Thanks a lot!

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.