• Resolved ShinichiN

    (@shinichin)


    I read Codex > Nginx and succeeded to have network install (subdirectory).

    But I have two problems with permalink settings ( https://example.com/wp-admin/options-permalink.php ).

    First, I see a slug /blog before input area.
    Second, there is a slug /index.php/ in the input area.

    Please see screenshot.

    I can’t get rid of either of them.
    (/blog is uneditable, and /index.php/ appears every time even I submit without /index.php/…:( )

    I have these problems only at the main (blog id = 1) site.

    Please if you know how to fix it, please let me know.

    Here is my nginx config files.

    nginx.conf:

    user              nginx;
    worker_processes  2;
    error_log  /var/log/nginx/error.log;
    pid        /var/run/nginx.pid;
    
    events {
        worker_connections  1024;
    }
    
    http {
    	include	/etc/nginx/mime.types;
    	default_type 	application/octet-stream;
    	access_log	/var/log/nginx/access.log;
    	sendfile        on;
    	#tcp_nopush     on;
    	keepalive_timeout  3;
    	#tcp_nodelay	on;
    	gzip  on;
    	#client_max_body_size 13m;
    	index      index.php index.html index.htm;
    	log_not_found off;
    
    #	Upstream to abstract backend connection(s) for PHP.
    #	upstream php {
    #		server unix:/tmp/php-fpm.sock;
    #		server 127.0.0.1:9000;
    #	}
    
    	include		sites-enabled/*;
    
    	server {
    	listen       80;
    	server_name  example.com;
    	root /var/www/vhosts/example.com;
    
    	if ($http_host != "example.com") {
    		rewrite ^ https://example.com$request_uri permanent;
    	}
    
    	include global/restrictions.conf;
    	include global/wordpress-ms-subdir.conf;
    	access_log /var/log/nginx/colog.jp.access.log;
    
    	}# end server{}
    
    }# end http {}

    global/wordpress-ms-subdir.conf:

    # This order might seem weird - this is attempted to match last if rules below fail.
    # https://wiki.nginx.org/HttpCoreModule
    location / {
    	try_files $uri $uri/ /index.php?$args;
    }
    
    # https://j.mp/ni5J6W
    ##necessary if using a multi-site plugin
    server_name_in_redirect off;
    ##necessary if running Nginx behind a reverse-proxy
    #port_in_redirect off;
    
    # Add trailing slash to */wp-admin requests.
    rewrite /wp-admin$ $scheme://$host$uri/ permanent;
    
    # Directives to send expires headers and turn off 404 error logging.
    location ~ .*\.(txt|xml|html?|jpe?g|JPE?G|gif|GIF|png|PNG|swf|SWF|wmv|WMV|flv|FLV|css|CSS|js|JS|inc|ico|gz) {
    	expires 24h;
    	log_not_found off;
    	break;
    }
    
    # Pass uploaded files to wp-includes/ms-files.php.
    rewrite /files/$ /index.php last;
    
    # For multisite:  Use a caching plugin that creates symlinks to the correct subdirectory structure to get some performance gains.
    set $cachetest "$document_root/wp-content/cache/ms-filemap/${host}${uri}";
    if ($uri ~ /$) {
    	set $cachetest "";
    }
    if (-f $cachetest) {
    	# Rewrites the URI and stops rewrite processing so it doesn't start over and attempt to pass it to the next rule.
    	rewrite ^ /wp-content/cache/ms-filemap/${host}${uri} break;
    }
    
    if ($uri !~ wp-content/plugins) {
    	rewrite /files/(.+)$ /wp-includes/ms-files.php?file=$1 last;
    }
    
    # Uncomment one of the lines below for the appropriate caching plugin (if used).
    #include global/wordpress-ms-subdir-wp-super-cache.conf;
    #include global/wordpress-ms-subdir-w3-total-cache.conf;
    
    # Rewrite multisite '.../wp-.*' and '.../*.php'.
    if (!-e $request_filename) {
    	rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
    	rewrite ^/[_0-9a-zA-Z-]+.*(/wp-admin/.*\.php)$ $1 last;
    	rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
    	rewrite ^.*$ /index.php last;
    }
    # Pass all .php files onto a php-fpm/php-fcgi server.
    location ~ \.php$ {
    	root 			html;
    	fastcgi_pass	127.0.0.1:9000;
    	fastcgi_index	index.php;
    	fastcgi_param	SCRIPT_FILENAME /var/www/vhosts/colog.jp$fastcgi_script_name;
    	include			fastcgi_params;
    }

    Thanks.

Viewing 15 replies - 1 through 15 (of 16 total)
  • Thread Starter ShinichiN

    (@shinichin)

    I reinstalled now subdomain with same code I wrote.

    And it worked very well.

    I didn’t get any /blog/ slug before input area or /index.php/ slug in ther input area..

    Is there anyone who has the same problem with me??

    Thanks..

    Thread Starter ShinichiN

    (@shinichin)

    I still don’t know how to fix it…

    Here are the wrong urls and how I want to fix.

    Wrong sample page url:
    https://example.com/index.php/sample-page
    I want:
    https://example.com/sample-page

    Wrong category page url:
    https://example.com/index.php/category/uncategorized
    It should be:
    https://example.com/category/uncategorized

    Wrong first post page url:
    https://example.com/index.php/2011/08/21/1
    It should be:
    https://example.com/2011/08/21/1

    The front page is displayed as https://example.com/ which is ok.

    I can’t get rid of index.php/ at “Permalink Setting” page. index.php/ appears always even I submit without this slug…

    Thread Starter ShinichiN

    (@shinichin)

    I fixed it.
    … not really but almost..

    I don’t get any /blog slug any more.

    I still get /index.php slug but I do as follows

    1. Define my permalink customize when it’s single install.

    2. Never touch permalink submit after multi-sited.

    3. You can change permalink structure if you define( ‘MULTISITE’, false );.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    First, I see a slug /blog before input area.

    Rolling back to that… I was avoiding this thread b/c I don’t know nginx well, but I DO know WordPress, and the blog slug is hard coded in if you’re using subfolder installs. You shouldn’t change that.

    Thread Starter ShinichiN

    (@shinichin)

    Thank you for the reply!
    I’m glad to know someone cared about my thread ??

    Now I don’t have the /blog slug.
    I customize my permalink as single-installed wp user, which is realized by changin define( ‘MULTISITE’, false ); at wp-config.php, and then come back to multi-sited wp.

    Is this going to cause any trouble to my site?

    I guess /blog slug is required to distinguish the main site from other child blogs..
    Is it something about performance?

    The main site doesn’t have /blog slug when it’s multi-sited.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    I guess /blog slug is required to distinguish the main site from other child blogs..
    Is it something about performance?

    Yes and yes. The main site will have /blog slug ONLY if you’re using subfolders (subdomains don’t have it).

    Thread Starter ShinichiN

    (@shinichin)

    Thank you Ipstenu!

    Is there any problem to leave the setting as it is?
    I mean that I don’t insert /blog slug (it’s possible to set permalink setting as single wp user and then get multi-sited).

    If it is possible to cause a serious trouble, can I change /blog to something else like /home or /main?

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    It can cause problems with any blogs named ‘blog’, but if you make sure not to do THAT, you’re okay.

    You can’t (currently) rename it. it’s actually hard coded into the permalink page. If you save permalinks, it SHOULD force it back it (it does on .htaccess/apache sites, dunno if nginx makes it different).

    Thread Starter ShinichiN

    (@shinichin)

    Thanks!

    I guess /blog slug is not able to be used as new child blog slug for it’s listed as unavailable in the network setting page.
    And maybe I shouldn’t /blog as category/tag slugs..:|

    And ofcourse I’ll avoid clicking submit button at permalink setting page:)

    Thanks, Ipstenu!
    Now my questions are all resolved!
    I hope this thread will be good for the wp community too!

    mikeatkc

    (@mikeatkc)

    How did you fixed the issue? I saw you post your config and then it doesn’t work and then it worked. What did you do? I’m running nginx 0.8.54 and WP 3.2.1 (not multisite). If I changed the PERMALINKS from “Default” to “Day and name” all my links are broken and so does some plugins.

    Is it as simple as having the rewrite rule below in nginx.conf?

    if ($http_host != "example.com") {
    		rewrite ^ https://example.com$request_uri permanent;

    mikeatkc

    (@mikeatkc)

    Discovered another post, the below links help:

    https://www.ads-software.com/support/topic/working-nginx-rewrite-rules-for-wordpress-multisite-3x-wp-super-cache?replies=12
    
    https://wiki.nginx.org/Wordpress

    Thread Starter ShinichiN

    (@shinichin)

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    That plugin doesn’t work with 3.2 last I checked.

    Add this to functions.php

    add_filter( 'got_rewrite', '__return_true', 999 );

    WordPress is checking if mod_rewrite is enabled (which of course it’s not since we aren’t using Apache), so force this to return true and it won’t add the additional index.php into the permalinks.

    Then, just save your permalinks again and you should be good to go.

    Hi,

    Use Nginx Compatibility by Vladimir Kolesnikov to setup your permalinks running on nginx (it does basically the same thing as defunctlife wrote above + more)

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘permalink problem on nginx’ is closed to new replies.