Nginx+Wordpress+Permalinks|来自服务器块的奇怪行为



我已经两天在尝试各种可能的配置了。我已经走了一半,但从来没有走完。

这是在我的硬盘死后在远程服务器上完成的,安装了全新的Debian 9.14。MariaDB+php7.0-fpm+nginx 1.10.3

我可以访问主页&Wp管理员,但所有其他页面在自定义永久链接时都是404。当永久链接处于平原时,我可以访问所有内容。

我有几个网站,所有人都有相同的问题。

我的文件夹结构是:/var/www/website1/&amp/var/www/website2/等…

这是我的nginx配置:

/etc/nginx/站点可用/默认

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;
}
}

注意:从那里开始,我显然不需要为其他网站设置任何其他配置文件。。。我可以用这个访问它们。这正常吗?在以前的服务器上,我必须创建每个站点的配置文件

不过,这里有一个

/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;
}
}

但正如我所说,无论有没有那个文件,我都可以访问网站1。事实上,我只需使用默认配置文件就可以访问它(或/var/www/中的任何其他网站(,这对我来说似乎很奇怪…但永久链接问题仍然存在。

/etc/nginx/nginix.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/*;
}

我不是一个nginx专家,总是在配置上遇到困难,但总是想明白。但在这里,我真的感觉被卡住了。谢谢你的帮助!


更新

我设法让永久链接在网站1上工作,但现在我不知道如何添加其他主机。

这是新文件。它也是唯一使用的配置文件。没有/etc/nginx/site可用/website1被使用。。。

/etc/nginx/站点可用/默认

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;
}
}

我终于找到了一些有效的东西。请告诉我最佳实践是否正确,如果不正确,我应该如何做?

在这里的配置是有效的,我只使用一个文件来声明所有网站。。。

/etc/nginx/站点可用/默认

server {
listen 80;
listen [::]:80;
root /var/www;
index  index.php index.html index.htm;
server_name  xx.xxx.xx.xxx;
client_max_body_size 100M;
location ~ .php$ {
include         snippets/fastcgi-php.conf;
fastcgi_pass    unix:/var/run/php/php7.0-fpm.sock;
fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location /website1 {
root /var/www;
try_files $uri /website1 /index.php?$args;
}
location /website2{
root /var/www;
try_files $uri /website2/index.php?$args;
}
location /website3{
root /var/www;
try_files $uri /website3/index.php?$args;
}    
}

最新更新