digitalocean / nginxconfig.io

⚙️ NGINX config generator on steroids 💉
https://do.co/nginxconfig
MIT License
27.66k stars 2.04k forks source link

Does nginxconfig.io support subpath configuration for Wordpress? #421

Open mehdiMj-ir opened 1 year ago

mehdiMj-ir commented 1 year ago

Information

https://whatismybrowser.com/w/5DDRK4Q

Help request

How to setup a Wordpress on a subpath with nginx?

Problem

I want Nginx configuration for Wordpress on a subpath, but didn't found any.

What I have tried

I tried to serve my blog located on /var/www/blog with this configuration but I couldn't succeed, (BTW my / is reverse peroxided and serve another application).

upstream php-srv {
  server unix:/run/php/php8.1-fpm.sock;
}

server {

  listen 443 ssl http2;
  #listen 443 ssl http2;
  ssl_certificate /etc/ssl/certs/domain.pem;
  ssl_certificate_key /etc/ssl/private/domain.key;
  server_name my.domain.com;
  #add_header 'Content-Security-Policy' 'upgrade-insecure-requests';

  location = /blog/robots.txt {
    allow all;
    log_not_found off;
    access_log off;
  }

  location ~ /\. {
    deny all;
  }

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

    location ~ \.php$ {
      fastcgi_split_path_info ^(/blog)(/.*)$;
      include fastcgi_params;
      fastcgi_intercept_errors on; # off later #####
      fastcgi_pass php-srv;
  #    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
      fastcgi_param  SCRIPT_FILENAME /var/www/blog$fastcgi_script_name;
    }

  location / {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $host;
    proxy_pass http://127.0.0.1:1081$request_uri;
    include /etc/nginx/mime.types;
  }

}

server {
  listen 80;
  server_name my.domain.com;
  return 301 https://$host$request_uri;
}

Screenshots

Here is my first try with your app:

Screenshot_20230217_232134

mehdiMj-ir commented 1 year ago

If anyone find how to solve this problem, help this poor soul too:

https://www.digitalocean.com/community/questions/getting-404-not-found-nginx-while-trying-to-visit-wordpress-post

TauqueerAhmad commented 1 year ago

Clear the browser cache and cookies. Set your permalinks. Make a default .htaccess file. Set up a 301 redirect. Disable plugins and themes. Change and update the WordPress URL in the database. Fix the error on local servers.

TauqueerAhmad commented 1 year ago

I think this can help you out

mehdiMj-ir commented 1 year ago

Clear the browser cache and cookies. Set your permalinks. Make a default .htaccess file. Set up a 301 redirect. Disable plugins and themes. Change and update the WordPress URL in the database. Fix the error on local servers.

Nginx doesn't support .htaccess, I use curl on my terminal so there is no browser or caching. BTW I already fix my path and address on wp database.

Thanks for your comment but this doesn't resolve the issue.