1

In nginx server the scenario is installing Wordpress in subfolder mydomain.com/new with domain specific nginx configuration (conf.d/mydomain.com.conf) below:

server  {
listen 80;
server_name mydomain.com *.mydomain.com;
root    /var/www/mydomain;
index   index.php index.html index.htm;
# error_log  /var/log/nginx/mydomain-error.log warn;

aio threads;
    set_real_ip_from 127.0.0.1;
    set_real_ip_from 10.0.0.0/8;
    real_ip_header X-Real-IP;
    add_header      Via     "1.1 varnish-v4.1";
    gzip_vary       off; # already handled from upstream server

    include includes/cloudflare.conf;
    include includes/fastcgi-wordpress.conf;

location / {
    try_files $uri $uri/ /index.php?$args /index.php?q=$uri&$args;
    expires 30d;
}

    # Deny access to uploads that aren’t images, videos, music, etc.
    location ~* ^/wp-content/uploads/.*.(html|htm|shtml|php|js|swf)$ {
        deny all;
    }

    # Deny public access to wp-config.php
    location ~* wp-config.php {
        deny all;
    }

    # Deny access to wp-login.php. Do not enable due to admin-ajax.php!! T_T
    # location = /(wp-login|login).php {
    #    limit_req zone=one burst=1 nodelay;
    #    fastcgi_pass 127.0.0.1:9000;
    # }

    location ~ \.php$ {
            try_files $uri /index.php;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
            include includes/fastcgi-http.conf;
    }

# location ~ /purge(/.*) {
#     fastcgi_cache_purge WORDPRESS "$scheme$request_method$host$1";
# }  

location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|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;
}

location ~ /\. {
    deny  all; 
    access_log off;
    log_not_found off;
}

}

The mydomain.com is running fine but in mydomain.com/new | all media and permalinks keep redirected to mydomain.com instead of mydomain.com/new. Which configuration should be modified to fix this? I'm new to this nginx configuration and how to prevent whole server/domain error if configuration failed (there's multi domain in this server) Many Thanks for the the help.

3

The problem resolved, I just need to add a location entry as follow:

location /new {
    try_files $uri $uri/ /new/index.php?$args /new/index.php?q=$uri&$args;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.