• Resolved theoni

    (@theoni)


    Hello,

    I know that there are several topics regarding permalinks, nginx and wordpress but our problem seems to persist..

    We have a main wordpress site installed in a root directory and a second wordpress site installed in a subdirectory of the root directory (for a second language, /en). Permalinks work fine in the main site but they don’ t in the second…only default format works, once we change it to any other we get a 404 error…Could you help? Thank you in advance! The nginx conf file is as follows:

    #
    # The default server
    #
    server {
    	listen       80;
    
    	server_name_in_redirect off;
    
    	root   /shared;
    	index  index.php index.htm index.html;
    
    	#charset koi8-r;
    
    	#access_log  logs/host.access.log  main;
    	#access_log off;
    
       proxy_set_header X-Forwarded-Proto $scheme;
    
    	  set $myhttps "";
             if ( $http_https = ON) {
               set $myhttps on;
             }
    
    	location ~ /phpMyAdmin {
    		   root /usr/share/;
    		   index index.php index.html index.htm;
    	            fastcgi_buffer_size 128k;
    		    fastcgi_buffers 256 4k;
    		    fastcgi_busy_buffers_size 256k;
    		    fastcgi_temp_file_write_size 256k;
    		    fastcgi_read_timeout 240;
    
    		   location ~ ^/phpMyAdmin/(.+\.php)$ {
    				fastcgi_pass   127.0.0.1:9000;
    				fastcgi_index  index.php;
    				include        fastcgi_params;
    				include /etc/nginx/fastcgi.conf;
    				fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    
    			}
    			if (!-e $request_filename)
    			{
    				rewrite  ^/(.*)/index.php/(.*)$  /$1/index.php  last;
    
    			}
    	}	
    
        location / {
    
    			try_files $uri $uri/ /index.php?$args;
    
        }
    
    	location /en {
    
    			try_files $uri $uri/ /index.php?$args;
    
        }
    
    	#location ~* /(images|cache|media|logs|tmp)/.*\.(php|pl|py|jsp|asp|sh|cgi)$ {
        #            return 403;
        #            error_page 403 /403_error.html;
        #    }
    
        error_page  404              /404.php;
        location = /404.php {
            root   /shared/ypaithrosxwra/wp-content/themes/Newspaper-child;
        }
    
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
    
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
    
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
    
    	location ~ \.php$ {
    
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            include        fastcgi_params;
    		include /etc/nginx/fastcgi.conf;
    		fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    		fastcgi_param HTTPS $myhttps;
    		fastcgi_param PATH_INFO $fastcgi_script_name;
    		fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
    
        }
    
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\. {
            deny  all;
    		access_log off;
    		log_not_found off;
        }
    
    	location ~ /htac {
            deny  all;
        }
    
        location ~ /\.ht {
            deny  all;
        }
    
    	location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
    		access_log off;	log_not_found off; expires max;
    	}
    
    	location = /robots.txt { access_log off; log_not_found off; }
    
    }
Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi,

    Try changing:

    location /en {
    try_files $uri $uri/ /index.php?$args;
    }

    to

    location /en {
    try_files $uri $uri/ /en/index.php?$args;
    }

    reload nginx and let us know if it did the trick 🙂

    Thread Starter theoni

    (@theoni)

    Hello!!!
    So sorry it took me 4 days to reply!
    Yes, that did the trick, thanks a lot 🙂
    Rookie mistake I guess…

    I have the same problem, The parmalinks are working fine on my website, but not working on sub-directory named it demo. My nginx.conf file is as below :
    Can anybody help me to resolve it

    # For more information on configuration, see:
    #   * Official English Documentation: http://nginx.org/en/docs/
    #   * Official Russian Documentation: http://nginx.org/ru/docs/
    
    user
    nginx;
    
    worker_processes  4;
    
    error_log  /var/log/nginx/error.log;
    
    #error_log  /var/log/nginx/error.log  notice;
    #error_log  /var/log/nginx/error.log  info;
    
    pid        /var/run/nginx.pid;
    
    events {
        worker_connections  1024;
    }
    
    http {
        include       /etc/nginx/mime.types;
        default_type  application/octet-stream;
    
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
    
        access_log  /var/log/nginx/access.log  main;
    
        sendfile        on;
        #tcp_nopush     on;
    
        #keepalive_timeout  0;
        keepalive_timeout  65;
        keepalive_disable msie6;
    
        #gzip  on;
    gzip on;
    	gzip_disable "msie6";
    
    	gzip_vary on;
    	gzip_proxied any;
    	gzip_comp_level 3;
    	gzip_buffers 16 8k;
    	gzip_http_version 1.1;
    	gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
    
    	geoip_country  /etc/nginx/geodata/GeoIP.dat;
    	geoip_city     /etc/nginx/geodata/GeoLiteCity.dat;    
    
        # Load config files from the /etc/nginx/conf.d directory
        # The default server is in conf.d/default.conf
        include /etc/nginx/conf.d/*.conf;
    
    }
    
    # worker_processes 1;
    # events {
    #	worker_connections  1024;
    # }
    http {
    	include       mime.types;
    	default_type  application/octet-stream;
    	log_format main '[$time_local] $remote_addr - $remote_user - $server_name  to: $upstream_addr: $request upstream_response_time $upstream_response_time msec $msec request_time $request_time status $status bytes $body_bytes_sent';
    	#Uncomment to debug rewrite rules
    	#rewrite_log  on;
    	server {
    		ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    
    		listen       81;
    		server_name  test1.com;
    		access_log  /var/log/nginx/test1.access.log  main;
    		# access_log  logs/test1.access.log  main;
    		#Uncomment to debug rewrite rules
    		#error_log    logs/rewrite.log notice;
    		root /usr/local/test1;
    		index index.php;
    
    		# WORDFENCE FALCON ENGINE CODE
    		#Match on gzip first because ordering matters.
    		location ~ "/site/wp-content/wfcache/.*gzip$" {
    		    gzip off;
    		    types {}
    		    default_type text/html;
    		    add_header Vary "Accept-Encoding, Cookie";
    		    add_header Content-Encoding gzip;
    		}
    		#If the previous matched, the following location won't be executed.
    		location ~ /site/wp-content/wfcache/.* {
    		    add_header Vary "Accept-Encoding, Cookie";
    		}
    		set $wordfenceCacheOn 1;
    
    		#Don't cache form submissions.
    		if ($request_method = POST) {
    			set $wordfenceCacheOn 0;
    		}
    
    		#Allow caching of /?123=123 because this is a common DDoS to override caches.
    		if ($query_string !~ "^(?:\d+=\d+)?$") {
    		    set $wordfenceCacheOn 0;
    		}
    
    		#Only cache URL's ending in /
    		if ($request_uri !~ \/$) {
    			set $wordfenceCacheOn 0;
    		}
    		#Don't cache any cookies with this in their names e.g. users who are logged in.
    		if ($http_cookie ~* "(comment_author|wp\-postpass|wf_logout|wordpress_logged_in|wptouch_switch_toggle|wpmp_switcher)") {
    		    set $wordfenceCacheOn 0;
    		}
    		set $wordfenceEncoding "";
    		#Oh, you want gzipped content?
    		if ($http_accept_encoding ~ gzip) {
    		    set $wordfenceEncoding _gzip;
    		}
    		set $wordfenceHTTPS "";
    		if ($scheme = 'https'){
    			#If you want to ENABLE HTTPS caching, comment out the next line.
    			set $wordfenceCacheOn 0; #Comment this line out to enable HTTPS caching.
    
    			set $wordfenceHTTPS '_https'; #Uncomment this line to enable HTTPS caching.
    		}
    		#The main purpose of this line is to capture the URL components into variables.
    		if ($request_uri !~ "^\/*(?<wfone>[^\/]*)\/*(?<wftwo>[^\/]*)\/*(?<wfthree>[^\/]*)\/*(?<wffour>[^\/]*)\/*(?<wffive>[^\/]*)(?<wfsix>.*)$"){
    			set $wordfenceCacheOn 0;
    		}
    		#If the file doesn't exist then don't serve from cache.
    		if (!-f "$document_root/site/wp-content/wfcache/${http_host}_${wfone}/${wftwo}~${wfthree}~${wffour}~${wffive}~${wfsix}_wfcache${wordfenceHTTPS}.html${wordfenceEncoding}") {
    		  set $wordfenceCacheOn 0;
    		}
    
    		if ($wordfenceCacheOn = 1) {
    		    rewrite .* "/site/wp-content/wfcache/${http_host}_${wfone}/${wftwo}~${wfthree}~${wffour}~${wffive}~${wfsix}_wfcache${wordfenceHTTPS}.html${wordfenceEncoding}" last;
    		}
    		# END Wordfence Rules
    
    		location / {
    			try_files $uri $uri/ /index.php?$args ;
    		}
    
    		location /demo {
    			try_files $uri $uri/ /demo/index.php?$args;
    			}
    
    		location ~ .php$ {
    			try_files $uri /index.php;
    			include fastcgi_params;
    			fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name;
    			fastcgi_pass unix:/var/run/php5-fpm.sock;
    		}
    	}
    }

    I’m having the same issue can someone help me?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Problem with permalinks in wordpress site within subfolder – we use nginx’ is closed to new replies.