已经两天了,我正在尝试所有可能的配置。我到了一半,但从来没有。
这是在我的HDD死后在具有全新Debian 9.14安装的远程服务器上完成的。 MariaDB + php7.0-fpm + nginx 1.10.3
我可以访问Homepage&Wp-admin,但是在自定义永久链接中,所有其他页面均为404。固定链接位于平原时,我可以访问所有内容。
我有几个网站,所有网站都一样。
我的文件夹结构是:/ var / www / website1 / && / var / www / website2 /等...
这是我的Nginx配置:
/ 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;
}
}
注意:从那里,我显然不需要为其他网站设置任何其他配置文件...我可以通过它来访问它们。这正常吗?在以前的服务器上,我必须创建每个站点的配置文件。
还是,这是其中之一
/ 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;
}
}
但是正如我所说的,无论有没有该文件,我都可以访问website1。我可以使用默认配置文件访问它(或/ var / www /中的任何其他网站)的事实对我来说很奇怪...仍然存在永久链接问题。
/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/*;
}
我不是Nginx专家,并且在配置方面总是很费力,但总是想出办法。但是在这里,我真的很困。 感谢您的帮助!
我设法使永久链接可以在website1上使用,但是现在我不知道如何添加其他主机。
这是新文件。它也是唯一使用的配置文件。没有使用/ etc / nginx / site-available / website1 ...
/ 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;
}
}
答案 0 :(得分:0)
我终于找到了可行的方法。请告诉我最佳做法是否正确,如果不正确,我应该怎么做?
这里的配置有效,我只用一个文件声明所有站点...
/ etc / nginx / site-available / default
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;
}
}