Wordpress Permalinks not working in Nginx Unicorn Meta Zoo #1: Why another podcast? ...

Second order approximation of the loss function (Deep learning book, 7.33)

Why didn't the Space Shuttle bounce back into space as many times as possible so as to lose a lot of kinetic energy up there?

Is a 5 watt UHF/VHF handheld considered QRP?

"Whatever a Russian does, they end up making the Kalashnikov gun"? Are there any similar proverbs in English?

Why does the Cisco show run command not show the full version, while the show version command does?

With indentation set to `0em`, when using a line break, there is still an indentation of a size of a space

Additive group of local rings

c++ diamond problem - How to call base method only once

Would reducing the reference voltage of an ADC have any effect on accuracy?

Do you need a weapon for Thunderous Smite, and the other 'Smite' spells?

Justification for leaving new position after a short time

Is accepting an invalid credit card number a security issue?

Are all CP/M-80 implementations binary compatible?

Does the set of sets which are elements of every set exist?

I preordered a game on my Xbox while on the home screen of my friend's account. Which of us owns the game?

Need of separate security plugins for both root and subfolder sites Wordpress?

What is this word supposed to be?

Align column where each cell has two decimals with siunitx

How to not starve gigantic beasts

How would I use different systems of magic when they are capable of the same effects?

How would this chord from "Rocket Man" be analyzed?

Function to calculate red-edgeNDVI in Google Earth Engine

Putting Ant-Man on house arrest

Passing args from the bash script to the function in the script



Wordpress Permalinks not working in Nginx



Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar ManaraApache to Nginx mod_rewrite ruleHow do WordPress permalinks work?Nginx & UserDir & PHPNginx slow downloads even with low disk ioChange wordpress port number in nginxHow to make nginx connect php-fpm with 127.0.0.1, not server's public ip?Wordpress / NGINX configuration issueHow to serve multiple websites using one domain with pathNextcloud live doc editing w/ Collabora Online (CODE) cURL error 60: Peer's certificate issuer has been marked as not trusted by the userApache can access Windows share but not folders in itdokuwiki, nginx and farms





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I'm moving my wordpress blog from Apache to Nginx. I've tried multiple tutorials to get permalinks working but nothing is working for me. My website structure is like this:



main site -> www.localhost.com

wordpress blog -> www.localhost.com/blog


Website is in /var/www/html and wordpress is installed in /var/www/html/blog



I've read multiple articles and watched multiple videos but nothing seems to be working. Please let me know where I'm going wrong.



I've defined two server blocks in /etc/nginx/sites-available/default
one for main site and one for the blog.



# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;

# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;

root /var/www/html;

# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;

server_name _;

charset utf-8;
error_page 404 /404.php;

location /article {
rewrite ^/article.* / redirect;
}

#location / {
# try_files $uri $uri/ /loadpage.php?$args;
#}

location ~ .html$ {
try_files $uri /courses/index.php?$args;
}





# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .php$ {
include snippets/fastcgi-php.conf;
#
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# With php7.0-fpm:
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
include fastcgi_params;

}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /.ht {
deny all;
}
}



server {
listen 80;
listen [::]:80;
root /var/www/html/blog;
index index.php index.html index.htm;
server_name example.com www.example.com;

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


location ~ .php$ {
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_index index.php;
# fastcgi_pass unix:/var/run/php/php7.1-fpm.sock; #Ubuntu 17.10
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; #Ubuntu 17.04
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

}









share|improve this question























  • For clarification, both your main site and WordPress are under the same domain? You cannot have multiple server blocks for the same domain (unless the ports are different, but that's not the case here).

    – Thomas
    11 hours ago











  • Yes, both are under the same domain. I'm testing it on my localhost. So it is like localhost for main site and localhost/blog for wordpress site.

    – Axel
    11 hours ago











  • @Thomas Man, you're a life saver! I was at this problem since last 6-7 hours, kept changing my config under the 2nd server block but didn't even think about the 2nd server block creating problem on its own. Permalinks working like charm now.

    – Axel
    11 hours ago











  • Please post the comment as an answer so that I can mark it as an answer.

    – Axel
    11 hours ago


















0















I'm moving my wordpress blog from Apache to Nginx. I've tried multiple tutorials to get permalinks working but nothing is working for me. My website structure is like this:



main site -> www.localhost.com

wordpress blog -> www.localhost.com/blog


Website is in /var/www/html and wordpress is installed in /var/www/html/blog



I've read multiple articles and watched multiple videos but nothing seems to be working. Please let me know where I'm going wrong.



I've defined two server blocks in /etc/nginx/sites-available/default
one for main site and one for the blog.



# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;

# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;

root /var/www/html;

# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;

server_name _;

charset utf-8;
error_page 404 /404.php;

location /article {
rewrite ^/article.* / redirect;
}

#location / {
# try_files $uri $uri/ /loadpage.php?$args;
#}

location ~ .html$ {
try_files $uri /courses/index.php?$args;
}





# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .php$ {
include snippets/fastcgi-php.conf;
#
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# With php7.0-fpm:
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
include fastcgi_params;

}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /.ht {
deny all;
}
}



server {
listen 80;
listen [::]:80;
root /var/www/html/blog;
index index.php index.html index.htm;
server_name example.com www.example.com;

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


location ~ .php$ {
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_index index.php;
# fastcgi_pass unix:/var/run/php/php7.1-fpm.sock; #Ubuntu 17.10
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; #Ubuntu 17.04
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

}









share|improve this question























  • For clarification, both your main site and WordPress are under the same domain? You cannot have multiple server blocks for the same domain (unless the ports are different, but that's not the case here).

    – Thomas
    11 hours ago











  • Yes, both are under the same domain. I'm testing it on my localhost. So it is like localhost for main site and localhost/blog for wordpress site.

    – Axel
    11 hours ago











  • @Thomas Man, you're a life saver! I was at this problem since last 6-7 hours, kept changing my config under the 2nd server block but didn't even think about the 2nd server block creating problem on its own. Permalinks working like charm now.

    – Axel
    11 hours ago











  • Please post the comment as an answer so that I can mark it as an answer.

    – Axel
    11 hours ago














0












0








0








I'm moving my wordpress blog from Apache to Nginx. I've tried multiple tutorials to get permalinks working but nothing is working for me. My website structure is like this:



main site -> www.localhost.com

wordpress blog -> www.localhost.com/blog


Website is in /var/www/html and wordpress is installed in /var/www/html/blog



I've read multiple articles and watched multiple videos but nothing seems to be working. Please let me know where I'm going wrong.



I've defined two server blocks in /etc/nginx/sites-available/default
one for main site and one for the blog.



# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;

# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;

root /var/www/html;

# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;

server_name _;

charset utf-8;
error_page 404 /404.php;

location /article {
rewrite ^/article.* / redirect;
}

#location / {
# try_files $uri $uri/ /loadpage.php?$args;
#}

location ~ .html$ {
try_files $uri /courses/index.php?$args;
}





# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .php$ {
include snippets/fastcgi-php.conf;
#
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# With php7.0-fpm:
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
include fastcgi_params;

}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /.ht {
deny all;
}
}



server {
listen 80;
listen [::]:80;
root /var/www/html/blog;
index index.php index.html index.htm;
server_name example.com www.example.com;

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


location ~ .php$ {
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_index index.php;
# fastcgi_pass unix:/var/run/php/php7.1-fpm.sock; #Ubuntu 17.10
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; #Ubuntu 17.04
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

}









share|improve this question














I'm moving my wordpress blog from Apache to Nginx. I've tried multiple tutorials to get permalinks working but nothing is working for me. My website structure is like this:



main site -> www.localhost.com

wordpress blog -> www.localhost.com/blog


Website is in /var/www/html and wordpress is installed in /var/www/html/blog



I've read multiple articles and watched multiple videos but nothing seems to be working. Please let me know where I'm going wrong.



I've defined two server blocks in /etc/nginx/sites-available/default
one for main site and one for the blog.



# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;

# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;

root /var/www/html;

# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;

server_name _;

charset utf-8;
error_page 404 /404.php;

location /article {
rewrite ^/article.* / redirect;
}

#location / {
# try_files $uri $uri/ /loadpage.php?$args;
#}

location ~ .html$ {
try_files $uri /courses/index.php?$args;
}





# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .php$ {
include snippets/fastcgi-php.conf;
#
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# With php7.0-fpm:
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
include fastcgi_params;

}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /.ht {
deny all;
}
}



server {
listen 80;
listen [::]:80;
root /var/www/html/blog;
index index.php index.html index.htm;
server_name example.com www.example.com;

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


location ~ .php$ {
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_index index.php;
# fastcgi_pass unix:/var/run/php/php7.1-fpm.sock; #Ubuntu 17.10
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; #Ubuntu 17.04
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

}






apache-http-server nginx wordpress permalink






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 13 hours ago









AxelAxel

54




54













  • For clarification, both your main site and WordPress are under the same domain? You cannot have multiple server blocks for the same domain (unless the ports are different, but that's not the case here).

    – Thomas
    11 hours ago











  • Yes, both are under the same domain. I'm testing it on my localhost. So it is like localhost for main site and localhost/blog for wordpress site.

    – Axel
    11 hours ago











  • @Thomas Man, you're a life saver! I was at this problem since last 6-7 hours, kept changing my config under the 2nd server block but didn't even think about the 2nd server block creating problem on its own. Permalinks working like charm now.

    – Axel
    11 hours ago











  • Please post the comment as an answer so that I can mark it as an answer.

    – Axel
    11 hours ago



















  • For clarification, both your main site and WordPress are under the same domain? You cannot have multiple server blocks for the same domain (unless the ports are different, but that's not the case here).

    – Thomas
    11 hours ago











  • Yes, both are under the same domain. I'm testing it on my localhost. So it is like localhost for main site and localhost/blog for wordpress site.

    – Axel
    11 hours ago











  • @Thomas Man, you're a life saver! I was at this problem since last 6-7 hours, kept changing my config under the 2nd server block but didn't even think about the 2nd server block creating problem on its own. Permalinks working like charm now.

    – Axel
    11 hours ago











  • Please post the comment as an answer so that I can mark it as an answer.

    – Axel
    11 hours ago

















For clarification, both your main site and WordPress are under the same domain? You cannot have multiple server blocks for the same domain (unless the ports are different, but that's not the case here).

– Thomas
11 hours ago





For clarification, both your main site and WordPress are under the same domain? You cannot have multiple server blocks for the same domain (unless the ports are different, but that's not the case here).

– Thomas
11 hours ago













Yes, both are under the same domain. I'm testing it on my localhost. So it is like localhost for main site and localhost/blog for wordpress site.

– Axel
11 hours ago





Yes, both are under the same domain. I'm testing it on my localhost. So it is like localhost for main site and localhost/blog for wordpress site.

– Axel
11 hours ago













@Thomas Man, you're a life saver! I was at this problem since last 6-7 hours, kept changing my config under the 2nd server block but didn't even think about the 2nd server block creating problem on its own. Permalinks working like charm now.

– Axel
11 hours ago





@Thomas Man, you're a life saver! I was at this problem since last 6-7 hours, kept changing my config under the 2nd server block but didn't even think about the 2nd server block creating problem on its own. Permalinks working like charm now.

– Axel
11 hours ago













Please post the comment as an answer so that I can mark it as an answer.

– Axel
11 hours ago





Please post the comment as an answer so that I can mark it as an answer.

– Axel
11 hours ago










1 Answer
1






active

oldest

votes


















0














By creating multiple server blocks for the same domain you are effectively creating a collision between the virtual servers. server blocks define what Nginx will listen for. If there are multiple virtual servers for a given port, the request will be passed on to a virtual server with the best matching server_name. By having multiple identical virtual servers, Nginx will have no way of telling where to pass it to.



Your main site and WordPress are under the same domain (and the same port) and thus should go in a single virtual server. You separate them using location blocks.



Take caution with the Nginx block selection algorithm, regular expression blocks are always evaluated before normal blocks. In your example everything ending with .html is send to your main site. This may interfere with WordPress when it tries to use URI's ending with .html as well. To prevent this, you can use nested location blocks. By moving the regular expression location block inside / it will only be evaluated when the parent location matches. When a request comes in for /blog, the /blog location block will be the best matching one and therefore will be selected over the / one. Because the regular expression block is now nested inside there, it won't be evaluated for requests to WordPress.



# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;

# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;

root /var/www/html;

# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;

server_name _;

charset utf-8;
error_page 404 /404.php;

location /article {
rewrite ^/article.* / redirect;
}

location / {
location ~ .html$ {
try_files $uri /courses/index.php?$args;
}

try_files $uri $uri/ /loadpage.php?$args;
}

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

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .php$ {
include snippets/fastcgi-php.conf;
#
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# With php7.0-fpm:
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
include fastcgi_params;

}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /.ht {
deny all;
}
}





share|improve this answer


























  • Done! Thanks for the answer but even more for the great explanation and not just posting the answer. You've cleared so many doubts of mine.

    – Axel
    10 hours ago











  • @Axel No problem, I'm glad I could help. If you run into any more issues with the migration process, feel free to ping me. ;)

    – Thomas
    10 hours ago












Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1429016%2fwordpress-permalinks-not-working-in-nginx%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














By creating multiple server blocks for the same domain you are effectively creating a collision between the virtual servers. server blocks define what Nginx will listen for. If there are multiple virtual servers for a given port, the request will be passed on to a virtual server with the best matching server_name. By having multiple identical virtual servers, Nginx will have no way of telling where to pass it to.



Your main site and WordPress are under the same domain (and the same port) and thus should go in a single virtual server. You separate them using location blocks.



Take caution with the Nginx block selection algorithm, regular expression blocks are always evaluated before normal blocks. In your example everything ending with .html is send to your main site. This may interfere with WordPress when it tries to use URI's ending with .html as well. To prevent this, you can use nested location blocks. By moving the regular expression location block inside / it will only be evaluated when the parent location matches. When a request comes in for /blog, the /blog location block will be the best matching one and therefore will be selected over the / one. Because the regular expression block is now nested inside there, it won't be evaluated for requests to WordPress.



# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;

# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;

root /var/www/html;

# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;

server_name _;

charset utf-8;
error_page 404 /404.php;

location /article {
rewrite ^/article.* / redirect;
}

location / {
location ~ .html$ {
try_files $uri /courses/index.php?$args;
}

try_files $uri $uri/ /loadpage.php?$args;
}

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

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .php$ {
include snippets/fastcgi-php.conf;
#
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# With php7.0-fpm:
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
include fastcgi_params;

}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /.ht {
deny all;
}
}





share|improve this answer


























  • Done! Thanks for the answer but even more for the great explanation and not just posting the answer. You've cleared so many doubts of mine.

    – Axel
    10 hours ago











  • @Axel No problem, I'm glad I could help. If you run into any more issues with the migration process, feel free to ping me. ;)

    – Thomas
    10 hours ago
















0














By creating multiple server blocks for the same domain you are effectively creating a collision between the virtual servers. server blocks define what Nginx will listen for. If there are multiple virtual servers for a given port, the request will be passed on to a virtual server with the best matching server_name. By having multiple identical virtual servers, Nginx will have no way of telling where to pass it to.



Your main site and WordPress are under the same domain (and the same port) and thus should go in a single virtual server. You separate them using location blocks.



Take caution with the Nginx block selection algorithm, regular expression blocks are always evaluated before normal blocks. In your example everything ending with .html is send to your main site. This may interfere with WordPress when it tries to use URI's ending with .html as well. To prevent this, you can use nested location blocks. By moving the regular expression location block inside / it will only be evaluated when the parent location matches. When a request comes in for /blog, the /blog location block will be the best matching one and therefore will be selected over the / one. Because the regular expression block is now nested inside there, it won't be evaluated for requests to WordPress.



# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;

# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;

root /var/www/html;

# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;

server_name _;

charset utf-8;
error_page 404 /404.php;

location /article {
rewrite ^/article.* / redirect;
}

location / {
location ~ .html$ {
try_files $uri /courses/index.php?$args;
}

try_files $uri $uri/ /loadpage.php?$args;
}

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

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .php$ {
include snippets/fastcgi-php.conf;
#
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# With php7.0-fpm:
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
include fastcgi_params;

}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /.ht {
deny all;
}
}





share|improve this answer


























  • Done! Thanks for the answer but even more for the great explanation and not just posting the answer. You've cleared so many doubts of mine.

    – Axel
    10 hours ago











  • @Axel No problem, I'm glad I could help. If you run into any more issues with the migration process, feel free to ping me. ;)

    – Thomas
    10 hours ago














0












0








0







By creating multiple server blocks for the same domain you are effectively creating a collision between the virtual servers. server blocks define what Nginx will listen for. If there are multiple virtual servers for a given port, the request will be passed on to a virtual server with the best matching server_name. By having multiple identical virtual servers, Nginx will have no way of telling where to pass it to.



Your main site and WordPress are under the same domain (and the same port) and thus should go in a single virtual server. You separate them using location blocks.



Take caution with the Nginx block selection algorithm, regular expression blocks are always evaluated before normal blocks. In your example everything ending with .html is send to your main site. This may interfere with WordPress when it tries to use URI's ending with .html as well. To prevent this, you can use nested location blocks. By moving the regular expression location block inside / it will only be evaluated when the parent location matches. When a request comes in for /blog, the /blog location block will be the best matching one and therefore will be selected over the / one. Because the regular expression block is now nested inside there, it won't be evaluated for requests to WordPress.



# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;

# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;

root /var/www/html;

# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;

server_name _;

charset utf-8;
error_page 404 /404.php;

location /article {
rewrite ^/article.* / redirect;
}

location / {
location ~ .html$ {
try_files $uri /courses/index.php?$args;
}

try_files $uri $uri/ /loadpage.php?$args;
}

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

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .php$ {
include snippets/fastcgi-php.conf;
#
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# With php7.0-fpm:
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
include fastcgi_params;

}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /.ht {
deny all;
}
}





share|improve this answer















By creating multiple server blocks for the same domain you are effectively creating a collision between the virtual servers. server blocks define what Nginx will listen for. If there are multiple virtual servers for a given port, the request will be passed on to a virtual server with the best matching server_name. By having multiple identical virtual servers, Nginx will have no way of telling where to pass it to.



Your main site and WordPress are under the same domain (and the same port) and thus should go in a single virtual server. You separate them using location blocks.



Take caution with the Nginx block selection algorithm, regular expression blocks are always evaluated before normal blocks. In your example everything ending with .html is send to your main site. This may interfere with WordPress when it tries to use URI's ending with .html as well. To prevent this, you can use nested location blocks. By moving the regular expression location block inside / it will only be evaluated when the parent location matches. When a request comes in for /blog, the /blog location block will be the best matching one and therefore will be selected over the / one. Because the regular expression block is now nested inside there, it won't be evaluated for requests to WordPress.



# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;

# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;

root /var/www/html;

# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;

server_name _;

charset utf-8;
error_page 404 /404.php;

location /article {
rewrite ^/article.* / redirect;
}

location / {
location ~ .html$ {
try_files $uri /courses/index.php?$args;
}

try_files $uri $uri/ /loadpage.php?$args;
}

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

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .php$ {
include snippets/fastcgi-php.conf;
#
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# With php7.0-fpm:
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
include fastcgi_params;

}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /.ht {
deny all;
}
}






share|improve this answer














share|improve this answer



share|improve this answer








edited 10 hours ago

























answered 11 hours ago









ThomasThomas

13616




13616













  • Done! Thanks for the answer but even more for the great explanation and not just posting the answer. You've cleared so many doubts of mine.

    – Axel
    10 hours ago











  • @Axel No problem, I'm glad I could help. If you run into any more issues with the migration process, feel free to ping me. ;)

    – Thomas
    10 hours ago



















  • Done! Thanks for the answer but even more for the great explanation and not just posting the answer. You've cleared so many doubts of mine.

    – Axel
    10 hours ago











  • @Axel No problem, I'm glad I could help. If you run into any more issues with the migration process, feel free to ping me. ;)

    – Thomas
    10 hours ago

















Done! Thanks for the answer but even more for the great explanation and not just posting the answer. You've cleared so many doubts of mine.

– Axel
10 hours ago





Done! Thanks for the answer but even more for the great explanation and not just posting the answer. You've cleared so many doubts of mine.

– Axel
10 hours ago













@Axel No problem, I'm glad I could help. If you run into any more issues with the migration process, feel free to ping me. ;)

– Thomas
10 hours ago





@Axel No problem, I'm glad I could help. If you run into any more issues with the migration process, feel free to ping me. ;)

– Thomas
10 hours ago


















draft saved

draft discarded




















































Thanks for contributing an answer to Super User!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1429016%2fwordpress-permalinks-not-working-in-nginx%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Cannot install PyQt5 The Next CEO of Stack OverflowCannot install tcpreplay 3.4.4cannot...

Kapp-Putsch Acontecimentos | Outros artigos | Menu de navegação

Why did early computer designers eschew integers? The Next CEO of Stack OverflowWhat register...