It's been two days I'm trying every possible configurations. I'm getting half-way there, but never all the way.
It's done on a remote server with fresh Debian 9.14 install after my HDD died. MariaDB + php7.0-fpm + nginx 1.10.3
I can access the Homepage & Wp-admin, but all others pages are 404 when in custom permalinks. I can access everything when permalinks are in Plain.
I have several websites, same issue for all.
My folder structure is : /var/www/website1/ && /var/www/website2/ etc...
Here are my nginx config:
/etc/nginx/site-available/default
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www;
index index.php index.html index.htm index.nginx-debian.html;
server_name xx.xxx.xx.xxx;
location / {
try_files $uri $uri/ /index.php?$args;
#try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
NOTE: from there, I apparently don't need to setup any other config file for the other website... I can access them all just with that. Is this normal? On my previous server, I had to create per site config files.
Still, here is one of them
/etc/nginx/site-available/website1
server {
listen 80;
listen [::]:80;
server_name _;
root /var/www/website1;
charset utf-8;
index index.php index.html index.htm;
error_page 500 502 503 504 /50x.html;
location = /50x.html { root /usr/share/nginx/html; }
access_log /var/log/nginx/website-access.log combined;
error_log /var/log/nginx/website-error.log error;
if (!-e $request_filename) {
# Don't use `$uri` here, see https://github.com/yandex/gixy/issues/77
rewrite /wp-admin$ $scheme://$host$request_uri/ permanent;
rewrite ^(/[^/]+)?(/wp-.*) $2 last;
rewrite ^(/[^/]+)?(/.*\.php) $2 last;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
log_not_found off;
access_log off;
allow all;
}
location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
log_not_found off;
}
location / {
try_files $uri $uri/ /index.php?$args;
#try_files $uri $uri/ /website1/index.php?q=$uri&$args;
#try_files $uri $uri/ =404;
#satisfy any;
#allow all;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}
}
But as I say, with or without that file, I can access website1. The fact that I can access it (or any other website in /var/www/) just with the default config file seems weird to me... Still the permalink issue remains.
/etc/nginx/nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 1024;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
#tcp_nopush on;
#tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
index index.php index.html index.htm;
# Upstream to abstract backend connection(s) for PHP.
upstream php {
#this should match value of "listen" directive in php-fpm pool
server unix:/tmp/php-fpm.sock;
#server 127.0.0.1:9000;
}
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
I'm not an nginx expert and always had a hard time with its configuration, but always figured it out. But here I feel really stuck. Thanks for your help!
UPDATE
I managed to get the permalinks to work on website1, but now I can't figure out how to add other hosts.
Here is the new file. It's also the only config file used. No /etc/nginx/site-available/website1 is used...
/etc/nginx/site-available/default
server {
listen 80 default_server;
listen [::]:80 default_server;
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
ssl on;
ssl_certificate_key /etc/ssl/private/nginx.key;
ssl_certificate /etc/ssl/certs/nginx.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-$
ssl_prefer_server_ciphers on;
root /var/www/website1;
index index.php index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ /index.php?q=$uri$args;
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
if (!-e $request_filename) {
rewrite ^.*$ /index.php last;
}
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
include fastcgi.conf;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}