NGINX Wordpress install in subdirectory wrong script URL - wordpress

Switching from Apache to NGINX here :)
So I have Site A which sits on the root directory http://test.fake.com/ and works fine. I also have another Wordpress Site (B) where the root is http://test.fake.com/b/
All the front end pages for B load scripts and css like http://test.fake.com/test.fake.com/b/ which of course is incorrect. When I try to goto the Admin like http://test.fake.com/wp-admin/ I receive No input file specified. as the only output, also the URL changes to http://test.fake.com/test.fake.com/b/wp-login.php.
Here is a snippet of my NGINX config where I think the problem lies, please let me know if you need more info and be gentle on a NGINX n00b :P
location /b {
try_files $uri $uri/ /b/index.php$args;
}
location / {
# Set try_files according WP architecture
try_files $uri $uri/ /index.php$args;
}
Here is a snippet of B's wp-config file where I am setting the URLs
define('WP_HOME','http://test.fake.com/b');
define('WP_SITEURL','http:/test.fake.com/b');
I have no idea where the error lies :(
Thank you for viewing!

Related

How to fix nginx conf for static site?

I don't understand why my nginx.conf file does not work.
This is just supposed to serve a static web site.
Later I want to add a wordpress to /blog.
Currently I want to make the main static site work.
The related conf is this:
location / {
index index.html
root /var/www/html/xlanding;
try_files $uri $uri/ =406;
}
This nginx is dockerized. I log in to the docker container and I can confirm that /var/www/html/xlanding/ exists and there is an index.html file there.
When I visit the url I see a 406 error (just changed from 404 to confirm that block is entered). So the block is matched.
How can I fix this?
Ah, I missed a semicolon after the "index index.html".

Add location station in Nginx config file in Synology NAS

I need to modify the nginx config file (/etc/nginx/app.d/server.webstation-vhost.conf) to add one line, which is for Laravel routing work correctly.
location / { try_files $uri $uri/ /index.php?$query_string; }
The problem is /etc/nginx/app.d/server.webstation-vhost.conf will ALWAYS OVERWITTEN once reboot the NAS,
Does anybody having experience how to hand this problem.
Many Thanks !
Not sure if you figured this out, but if you haven't, under that vhost conf file (/etc/nginx/app.d/server.webstation-vhost.conf), look for something like:
include /usr/local/etc/nginx/conf.d/f2f0a62b-74d6-4c34-a745-d0156f13c9d6/user.conf*;
Instead of f2f0a62b-74d6-4c34-a745-d0156f13c9d6 you should see another unique id for your nginx app, create/edit the mentioned user.conf file (without asterisk) with the contents you need, in my case I created a file with the contents below:
location / {
try_files $uri $uri/ /index.html;
}
Then I had to restart nginx with the command sudo synoservice --restart nginx.
And it worked.
PS.: I believe it should work for any DSM v6.1 or later (maybe 6.0.x as well).
For research I used:
https://community.synology.com/enu/forum/1/post/122043
https://community.synology.com/enu/forum/1/post/120538

Nginx URL routing

I think this is kind of basic stuff, but I'm struggling to find proper guide that would explain these things:
I have a index.php file and nginx config so that https://dev.something.com works ok.
But I need to change nginx config so that that address produces blank page, and index.php only works from https://dev.something.com/lists. I could put index.php inside lists directory, but isn't there more subtle solution?
And here's the hard part:
Users should be able to access
https://dev.something.com/lists/userName
https://dev.something.com/lists/userName/listName
userName and listName should be used as GET-parameters.
Can anyone help how I could achieve this kind of config with nginx?
You're asking a few (relatively basic) questions, and I would suggest you start with their free e-book https://www.nginx.com/blog/announcing-oreillys-new-book-nginx-a-practical-guide-to-high-performance/
You can define where nginx looks for index files with the root clause, and though they normally use the URL context relative to the server's root, it can be override in each location.
http://nginx.org/en/docs/http/ngx_http_core_module.html#root
You can use portions of URLs as variables, which can be passed as paramters too.
location = /lists { # '=' will match exactly, no trailing url
root /path/where/index.php/lives;
try_files $uri /index.php;
}
location /lists { # this will match anything under that url
rewrite ^/lists/(\d+)/?$ /lists?user=$1; # matches username
rewrite ^/lists/(\d+)/(\d+)/?$ /lists?user=$1&list=$2; # matches username/list
}
location /{ #everything else
root /path/where/index.html/lives; #index.html is empty file.
try_files $uri /index.html;
}

nginx match specific file from different folder on certain routes

I have an angularjs app, it has a blog as well. This url shows all blog posts under
http://example.com/blog/
And specific blog posts under
http://example.com/blog/example-blog-post-title
Now i'm precompiling HTML of blog posts for SEO purposes and i want to serve them completely separately from my main app like this:
...
root "/home/ubuntu/client/public";
location / { ## Handle default requests ##
try_files $uri $uri/ /index.html;
}
location /blog { ## serve precompiled blog HTML
alias /home/ubuntu/bloghtml;
try_files $uri.html $uri/ index.html;
}
...
And this works, by going to http://example.com/blog/example-blog-post-title nginx successfully serves file /home/ubuntu/bloghtml/example-blog-post-title.html
However the issue is that in this case nginx doesn't correctly route blog post list under http://example.com/blog/ to my main angular app, i get error 403 on that URL.
I tried changing location /blog to location /blog/ in conf file, this makes the http://example.com/blog/ work, howewever i get 404 errors on http://example.com/blog/example-blog-post-title
How can i make this work for both cases?
If you change the location from /blog to /blog/ you need to remember to change alias from /home/ubuntu/bloghtml to /home/ubuntu/bloghtml/. The alias and location need to have the same ending, otherwise the calculated pathnames are wrong.
I try to avoid using alias and try_files in the same block because of some known issues. You might consider making the last directory in the path blog so that you can use root instead.
I presume that your angular app is /index.html, in which case your try_files statement is incorrect. The $url/ will cause it to try /blog/index.html (assuming you have an index directive in force) and index.html is missing a leading /.
I would suggest you try:
location /blog {
alias /home/ubuntu/bloghtml;
try_files $uri.html /index.html;
}
but consider designing out the alias directive too.

NGINX Server block when MediaWiki in subdirectory

MediaWiki installation was in domain.com/subdirectory and worked with Apache as the server.
Pages were found domain.com/subdirectory/index.php/Main_Page
The server was changed to NGINX the other night. WordPress and XenForo work fine but the location block for MediaWiki isn't working properly.
Since I'm new to NGINX and the configuration file inner workings, I'm not sure how to write the location block to get the results equal to the Apache page layout (index.php shows).
This is my latest attempt (failed, of course).
#MEDIAWIKI
location /subdirectory/ {
try_files $uri $uri /index.php?query_string;
}
This writes to domain.com/subdirectory/title and the index.php is missing.
The documents show writing to a subdomain and this is not what I'm wanting. The index.php also needs to remain.
Thank you for providing as much information so this is solved. For example, I'm not sure if LocalSettings needs modification.
Try adding
index index.php index.html;
Updated*
location /subdirectory/ {
index index.php index.html;
}
Using Rewrite
rewrite ^ /index.php?$request_uri;
this will forward requests to /subdirectory/index.php?
In your case, /subdirectory/index.php?/Main_Page

Resources