I have nginx running with php 7 fpm.
My Wordpress permalinks are setup with /%postname%/. assuming my domain is example.com I want to have permalinks like that: example.com/postname/ But this leads to an error. I can find the post with this link: example.com/index.php?postname/
How do I get rid of the index.php? in the links?
Edit
My Nginx config
server {
server_name localhost;
root /var/www/;
index index.html index.htm index.php;
location ~\.php$ {
try_files $uri =404;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param REQUEST_URI $args;
}
location / {
try_files $uri $uri/ /index.php$args;
}
location /wordpress/ {
try_files $uri $uri/ /wordpress/index.php?$args;
}
}
You question implies that WordPress is installed at location /, so I am not sure why you have a location /wordpress also.
There are some issues with your configuration.
The value for REQUEST_URI should be set to $request_uri which is probably already the default value in the fastcgi_params file. This is the parameter that index.php uses to decode the pretty permalink.
Delete the line fastcgi_param REQUEST_URI $args;.
Your try_files statement is missing a ?. Use either:
try_files $uri $uri/ /index.php?$args;
Or:
try_files $uri $uri/ /index.php;
I have found that passing $args to /index.php is not necessary with WordPress.
Related
My server application uses Laravel, and I have until recently had a wordpress blog hosted at blog.server.com
I wish to change this to server.com/blog
I have updated the main nginx config by adding the following:
location ^~ /blog {
root /home/ploi/blog.server.com/public;
index index.php index.html index.htm;
try_files $uri $uri/ /blog/index.php?$query_string;
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
fastcgi_buffers 16 16k;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
This kind of works. It loads the new /blog url and posts, but:
No static assets get loaded (js, png, css, etc)
server.com/blog/wp-admin/ loops infinitely
How can I solve this?
You could try this, worked for me:
location /blog {
alias /home/ploi/blog.server.com/public;
try_files $uri $uri/ #blogrewrite;
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
}
location #blogrewrite {
rewrite /blog/(.*)$ /blog/index.php?/$1 last;
}
I used a "named location" (#blogrewrite), but frankly I don't know why this was necessary, but it avoided the recursion.
I am trying to get URLs that looks like https://my.site.com/index.php/user/login to work on nginx.
From what I understand about server blocks, nginx thinks that index.php/user/login are either a path or a directory, so it doesn't process them correctly and dies with a 404.
My server block's try file looks like this:
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php$is_args$args;
# Enable CORS
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length';
}
What am I missing? All I need nginx to do is "aha! index.php is right there; my job is done", then the framework will realize that "ha! the whole URL is https://my.site.com/index.php/user/login; that means they want me to run the user controller, then load the login action" and that's it
I use Laravel which defaults to similar rewrites (no index.php in the url)
Here is a final structure that works well,
Explained here
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/laravel/public;
index index.php index.html index.htm;
server_name server_domain_or_IP;
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;
}
}
Can anyone done with Codeigniter setup with nginx for hmvc stucture?
Please help me on this, I try to setup up codeigniter HMVC structure on nginx. But fails to many times. Please suggest some wayt to configure it.
I am using php7.0-fpm.
My nginx config file is
server {
listen 80;
root /var/www/html/salsetrack;
index index.html index.htm index.php;
server_name local.sales-track.com;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
index index.html index.php;
try_files $uri $uri/ #handler;
expires 30d;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
try_files $uri =404;
#Include Nginx’s fastcgi configuration
include /etc/nginx/fastcgi.conf;
#Look for the FastCGI Process Manager at this location
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location #handler {
rewrite / /index.php;
}}
You can refer https://www.nginx.com/resources/wiki/start/topics/recipes/codeigniter/ for nginx configuration for codeigniter.
Although this issue has been answered many times but still its not working for me.
I am getting 404 on all pages except home page on Nginx.
I am posting in my configuration below:
server {
listen 80 ;
listen [::]:80;
root /var/www/html/p/swear;
index index.php index.html index.htm;
server_name skinnybikiniswimwear.org;
location / {
try_files $uri /$uri/ /index.php?args =404;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
try_files $uri /index.php?args =404;
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
I am not able to find the issue in this configuration.
Wordpress is installed at: /var/www/html/p/swear
Thanks
Try this :
location / {
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't break when using query string
try_files $uri $uri/ /index.php?$is_args$args =404;
}
if (!-e $request_filename) {
rewrite ^.*$ /index.php last;
}
Having had a lot of failures configuring wordpress to work with nginx, the rewrite rule solves every issue with the 404 errors.
try removing slash in front of /$uri/
location / {
try_files $uri $uri/ /index.php?$args ;
}
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_pass php;
}
Images does not because you dont have nothing in your server block about images. You have to add the images into your server block.
For example:
location ~* ^.+\.(jpe?g|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mp3)$ {
root /home/example/public_html
}
I have strange problem. On localhost everything is ok. But on my production website function Input::all() return empty Array.
For example http:://mypage.com?action=run etc.
nginx configuration
server {
root /usr/share/nginx/www/g2g/public;
index index.html index.htm index.php;
server_name mypage.com www.mypage.com;
location / {
try_files $uri $uri/ /index.html /index.php;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
Thanks, for help.
Should be.
location / {
try_files $uri $uri/ /index.html /index.php?query_string;
}
in nginx configuration file
In nginx configuration, it should be this.
location / {
try_files $uri $uri/ /index.html /index.php?$query_string;
}
This is important - $query_string
Hope much helpful with saving time.