0

I know there are other similar to this thread, but I already tried for days and can not get this through, currently, with the below nginx configuration on Ubuntu 18

server { listen 80; root /var/www/html/wordpress/public_html; index index.php index.html; server_name "example.com"; access_log /var/log/nginx/SUBDOMAIN.access.log; error_log /var/log/nginx/SUBDOMAIN.error.log; location /blog { index index.php index.html index.htm; try_files $uri $uri/ /blog/index.php?q=$uri&$args; location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.2-fpm.sock; } } location ~ /\.ht { deny all; } location = /favicon.ico { log_not_found off; access_log off; } location = /robots.txt { allow all; log_not_found off; access_log off; } location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { expires max; log_not_found off; }} 

Here is my folder current structure

  • /var/www/html/wordpress/public_html -> include folder blog and one simple index.html (not serving wordpress)
  • /var/www/html/wordpress/public_html/blog -> is my wordpress files location

However, there are two wrong parts I need to solve it.

  1. It display "mysite.com/blog" okay but when i click on any blog or url -> it shows " example.com/?p=1" and therefore leads the to simple index.html at location / (" example.com")
  2. I can not access to wp-admin also, it will redirect to this if i put "example.com/blog/wp-admin" -> "http://example.com/wp-login.php?redirect_to=http%3A%2F%2Fexample.com%2Fblog%2Fwp-admin%2F&reauth=1 -> then 404

Thank you so much.

Update 2: I tried changing the WP_SITEURL to example.com AND WP_HOME to example.com/blog also modified these 2 records in mysql wp-options table. however, when i tried access /blog/wp-admin -> http://example.com/blog/wp-admin/example.com/blog/wp-login.php?redirect_to=http%3A%2F%2Fexample.com%2Fblog%2Fwp-admin%2F&reauth=1 -> 404

4
  • You need to properly set up WP_HOME and WP_SITEURL WordPress configuration parameters; you can start reading from here. Commented Jun 14, 2022 at 18:03
  • I have tried the above, the 1st issue is solved but the 2nd issue, wp-admin is still not accessible. Do you have any ideas? @IvanShatsky Thank youu. Commented Jun 16, 2022 at 4:17
  • updated in the post Commented Jun 16, 2022 at 6:38
  • Why /blog/index.php?q=$uri&$args; and not just a /blog/index.php?$args;? Can't this redirect come from the browser cache? Can you try from the incognito browser window? Commented Jun 16, 2022 at 7:54

1 Answer 1

0

For sure you need

root /var/www/html/wordpress/public_html/blog; 

in the block location /blog {}

Moreover the block location ~ \.php$ should looks like below:

location ~ \.php$ { try_files $uri =404; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $request_filename; fastcgi_pass unix:/run/php/php7.2-fpm.sock; } 

also, you need to change try_files directive to try_files $uri $uri/ /blog/index.php?$args;

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.