I've just installed nginx 1.0.8 and php-fpm and for the last 30 minutes I'm trying to rewrite the URL for Wordpress.
Here is what the Wordpress URL should look like:
http://localhost/website/blog/2011/10/sample-post/
I've looked at this tutorial: http://wiki.nginx.org/WordPress + many other on the web but every time I receive an 404 error (sometimes 403).
Here is what I did in my configuration file:
location /website/blog {
try_files $uri $uri/ /website/blog/index.php;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
fastcgi_split_path_info ^(/website/blog)(/.*)$;
include fastcgi_params;
error_page 404 /404.html;
}
With this configuration I'm receiving "403 forbidden" status.
What am I missing?
Could be the permission of the root site folder
This is an example that i use to wordpress
server {
listen 80;
server_name www.mysite.com mysite.com;
root /srv/www/mysite.com/public_html;
location / {
index index.html index.htm index.php;
try_files $uri $uri/ /index.php?$args;
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
include /srv/www/mysite.com/public_html/*.conf;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Did you try restarting nginx after you have saved your config?
Also, check out my nginx/WordPress setup guide here:
http://themesforge.com/featured/high-performance-wordpress-part-3/
Related
NGINX doesn't see the routes, giving 404 NOT FOUND.
The website is located in /usr/share/nginx/html/website folder and accessed via http://localhost.
The route I'm accessing in the application is localhost/api/public/languages.
Here is my NGINX:
root /usr/share/nginx/html/website;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
error_log /var/log/php-fpm/www-error.log;
}
How to access the routes?
I currently have a WordPress site, which is currently installed on a subdirectory. However, there seems to be an issue.
The site appears as it supposed to, but the posts are either having a 404 error page and redirecting to the root of the site. Here is the screenshot of the setup I currently have on the server:
If anyone can please help me out here. I would appreciate it.
UPDATE (29/04/2018):
I have been working on this and it has come to a point where the blog page opens however, the posts are coming up with a 404 error message from the ROOT site.
For example:
When opening the subdirectory ( example.com/blog ), the site will appear. When clicking on a post, the 404 page will be displayed, but on the example.com site.
This makes me believe that there is an issue with the 2 WordPress installations however, I cannot be certain.
Here are my Nginx configurations for the root and the blog:
location /blog {
root /var/www/html/aus;
index index.php index.html;
access_log /var/log/nginx/blog.access.log;
error_log /var/log/nginx/blog.error.log;
try_files $uri $uri/ /blog/index.php$is_args$args;
if (!-e $request_filename) {
rewrite ^.*$ /blog/index.php last;
}
}
location / {
access_log /var/log/nginx/root.access.log;
error_log /var/log/nginx/root.error.log;
#try_files $uri $uri/ =404;
gzip off;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_intercept_errors on;
fastcgi_ignore_client_abort off;
reset_timedout_connection on;
include fastcgi.conf;
fastcgi_param SERVER_PORT 80;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
}
If you are getting 404 error page or some other error for posts, reset your permalinks setting.
Go to Settings → Permalinks and reset it to default settings and save it.
Your nginx config should be something like this:
upstream php-upstream {
server unix:/var/run/php5-fpm.sock fail_timeout=0;
}
...
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_intercept_errors on;
fastcgi_ignore_client_abort off;
reset_timedout_connection on;
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi.conf;
fastcgi_param SERVER_PORT 80;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass php-upstream;
fastcgi_index index.php;
}
...
That's an excerpt from a working nginx config for a wordpress website. Of course you should adapt it and modify it accordingly to suit your needs.
I am having a problem with my nginx (and php-fpm) virtual host configuration. The problem is all requests (except static files) return HTTP 500 (Internal Server Error)
Here is my nginx vh code
server {
listen 80;
root /var/www/somesite/public;
index index.php index.html index.htm;
server_name somesite.com;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
However when I serve using php's inbuilt development server everything works fine. FYI it's a laravel app
Thanks in advance
I have a Symfony site at /var/www/mysite/symfony and a WordPress blog at /var/www/mysite/wordpress. How can I direct mysite.com/blog to WordPress and all other requests to Symfony? Here's what I've tried so far:
server {
server_name mysite.com;
root /var/www/mysite/symfony/web;
location / {
try_files $uri /app.php$is_args$args;
}
location ~ ^/(app|app_dev|config)\.php(/|$) {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
}
location ~ ^/blog {
root /var/www/mysite/wordpress;
try_files $uri $uri/ /blog/index.php?$args;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
}
}
access_log /var/log/nginx/mysite-access.log;
error_log /var/log/nginx/mysite-error.log;
}
With this configuration I get a 'File not found.' error when I visit mysite.com/blog. My nginx log file shows FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream. I know it's not an issue with my php-fpm set up as Symfony runs fine at my site root.
Where am I going wrong?
I found a specific rule for installing wordpress in a subfolder:
# Replace all occurrences of [subfolder] with the folder where your WordPress install is located
# The WordPress rewrite
location /[subfolder] {
try_files $uri $uri/ /[subfolder]/index.php?$args;
}
# The default MODX rewrite</h1>
location / {
try_files $uri $uri/ #modx-rewrite;
}
Original post here: Web Rules: Nginx Rewrites, Redirects and other Cloud Configs | MODX Cloud
I have config(minimal):
server {
listen test.local:80;
server_name test.local;
server_name_in_redirect off;
location / {
root /data/www/test/public;
try_files $uri $uri/ /index.php?route=$uri&$args;
index index.html index.php;
}
location ~ \.php$ {
root /data/www/test/public;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www/test/public$fastcgi_script_name;
fastcgi_param ...
...
}
}
Thats work file for urls /help/ or /contacts/ etc… (all redirect to index.php with get variables).
But if url, for example, /help.php or contacts.php, and this files not exists, I have output:
File not found.
How update my Nginx config? I need URLs, for example:
/help.php => /index.php?route=/help.php
/contacts.php?foo=bar... => /index.php?route=/contacts.php&args=…
Here is simple config for 404 error page . Its custom 404 page.
error_page 404 /404.php;
location /404.php {
root /var/www/public_html;
allow all;
}
Last part
Important line is ========== try_files $uri =404;
location ~ .php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/public_html$fastcgi_script_name;
include fastcgi_params;
}