I am fairly new to server issues and I am trying to figure out what may cause the following issue.
I have a wordpress website and the folder structure is as follows:
httpdocs(folder) >
folder1 (which contains the wordpress instance for security purposes)
wp-config file (the actual wp-config file)
index.php (which "calls" ./folder1/wp-blog-header.php)
I seem to get 404 errors on every page except from the homepage.
The server support team tried to put
location = / {
index index.php;
try_files $uri $uri/ /index.php$is_args$args;
}
and later
location = /folder1 {
index index.php;
try_files $uri $uri/ /folder1/index.php$is_args$args;
}
on the nginx additional directives, but the problem persists.
To be specific, I get the following error:
20840#0: *number "/var/www/vhosts/sitename/httpdocs/pagename/index.php" is not found (2: No such file or directory)
Obviously, I am missing something. Can someone help me?
Related
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!
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.
When I try to use laravel PHP framework, I try to place it in a dir called /home/usr/proj/laravel, but as we know that the public html of laravel is settled in /home/usr/proj/laravel/public, thus my problem is how to make the setting of nginx such that when I access by mysite.com/laravel/ or mysite.com/laravel, we in fact redirected to the location laravel/public/index.php.
Also, it seems that there is a rule of nignx which is suggested by the official of laravel, to make the url looks pretty
location / {
try_files $uri $uri/ /index.php?$query_string;
}
How can I use this in my case?
UPDATE
It seems the following code works for me (but give me error NotFoundHttpException in RouteCollection.php line 145:, maybe caused by my router setting)
location /laravel{
root /home/usr/proj/laravel/public;
index index.php index.html;
try_files $uri $uri/ /laravel/public/index.php?$query_string;
}
Regarding your Update, I think that you should keep your original try_files syntax:
try_files $uri $uri/ /index.php?$query_string;
since the location is set to /laravel and the root is in the public folder. The way it is currently written ends up looking for file /home/usr/proj/laravel/public/public/index.php in the disk.
You should also check to configure your application URL so that it contains the /location part of the URL. I am not quite sure about how Laravel 5 is configured since my experience is with Laravel 4.
I'm running into an extremely bizarre error while running a WordPress site.
WordPress has permalinks turned on. The 500 server error occurs when you REMOVE the trailing slash (/) from the URL. For example:
www.site.com/about/ -> works fine.
www.site.com/about -> throws a 500 server error.
The error log show the following:
[Tue Sep 24 00:44:58 2013] [warn] [client 75.52.190.1] (104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server
[Tue Sep 24 00:44:58 2013] [error] [client 75.52.190.1] Premature end of script headers: index.php
Wordpress debug log is active, but no errors or warnings are being generated.
Other points to note:
The server has multiple domains managed under Plesk 11.5.
Only one of the domains suffers from this issue.
I compared the config vhost.conf files located in /var/www/system/domain/etc/ to another wordpress domain that is not having this issue. Everything is identical.
I also tried removing all of the wordpress files and uploaded a completely fresh copy. The problem still occurs, even with a fresh copy of WordPress and no plugins, templates, or anything else.
One last item that I noticed. My domain specific vhost.conf has the following info:
location ~ /$ {
index index.php index.cgi index.pl index.html index.xhtml index.htm index.shtml;
try_files $uri $uri/ /index.php?$args;
}
That seems to be looking for anything with a /. Should I remove the / or add a similar block? The only reason I haven't tried is because none of the domains suffer from this issue. My next course of action would be to download all domain conf files and diff them against the domain with the error. I'd rather not go down that path if possible.
Thanks!
You need to remove the $ from the location block, because this location only matches URL's that end with a /, and since you won't need regex then you can remove ~ too, so the final result is
location / {
# your rewrites and try_files
}
Strange, without
location ~ /$ {
try_files $uri /wordpress/index.php?$args;
}
I've got 404 error for permalinks. And with it everything working. Maybe it will helps someone.
The final, working code for me is as follows:
location ~ / {
index index.php index.cgi index.pl index.html index.xhtml index.htm index.shtml;
try_files $uri $uri/ /index.php?$args;
}
I'm having a problem with try_files not appearing to pass off requests for non-existent files to the last specified value, in my case index.php. I'm using Wordpress and the XML Sitemap generator plugin I use creates virtual XML files and a virtual robots.txt that's handled by Wordpress. Unfortunately try_files doesn't seem to be passing the requests for these files to Wordpress.
Here's my server configuration:
server {
## Web domain
server_name christiaanconover.com;
## Site root
root /var/www/christiaanconover.com;
## Index
index index.php index.htm;
## Common Wordpress configuration
include wp.conf;
## Include PHP configuration
include php.conf;
## Gzip Compression
include gzip.conf;
## Include W3TC configuration
include /var/www/w3tc/christiaanconover.com;
}
I run multiple separate Wordpress sites on this server, so to save time I created a file wp.conf that contains all the commonly used configuration elements for Wordpress. Here is the contents of wp.conf:
location / {
## Prevent PHP files from being served as static assets, and fall back to index.php if file does not exist
try_files $uri $uri/ /index.php?$args;
## If a file exists, serve it directly
if (-f $request_filename) {
break;
}
## Wordpress Rewrite
if (!-e $request_filename) {
rewrite ^ /index.php last;
}
}
Everything else is working perfectly, but the try_files arrangement just doesn't seem to hand off properly. Any ideas?
you're running into one of the problems described at http://wiki.nginx.org/IfIsEvil#Examples
the ifs you specified in the wp.conf are uneeded you already have them covered with your try_files, so you can just remove them, yielding:
location / {try_files $uri $uri/ /index.php$is_args$args;}
that will:
check if a file matching $uri (relative to the location specified by the root directive) exists
if not check if directory match exists
else redirect to /index.php$is_args$args
Where $is_args evaluates to ? when $args is set.