Viktoriya9999
@Viktoriya9999
Начинающий сис админ

Настройка Wordpress в ngix несколько сайтов, после добавления первого сайта последующие начинают редиректить на первый?

Добрый день. Подскажите пожалуйста. Настроила сервер, установила первый сайт на wordpress но при добавлении второго сайта, точнее после добавления второго сайта, проходит пару минут и он начинает редиректить на первый сайт. Даже после сноса бд и файлов второго сайта и заново если залить новые то все равно уже идет редирект на первый сайт.
php8.3
Redis
Сайты добавляю на сервер путем создания новых конфигов код ниже
# Rewrite с http
server {
    listen 80;
    listen [::]:80;
    server_name exemple.com www.exemple.com;
    return 301 https://$host$request_uri;
}

# Обработка https
server {
    # включаем http2 - ускоряет обработку (бинарность, мультиплексирование и т.д.)
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    ssl_certificate /etc/letsencrypt/live/www.exemple.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/www.exemple.com/privkey.pem;

    server_name exemple.com www.exemple.com;

    root /home/web/exemple.com;
    index index.php;

    include snippets/wp-supercache.conf; # подключаем файл с конфигом для WP Super Cache

    # Обрабатываем php файлы
    location ~ \.php$ {
        fastcgi_buffers 8 256k;
        fastcgi_buffer_size 128k;
        fastcgi_intercept_errors on;
        include fastcgi_params;

        fastcgi_cache microcache;
        fastcgi_cache_key $scheme$host$request_uri$request_method;
        fastcgi_cache_valid 200 301 302 30s;
        fastcgi_cache_use_stale updating error timeout invalid_header http_500;
        fastcgi_pass_header Set-Cookie;
        fastcgi_pass_header Cookie;
        fastcgi_ignore_headers Cache-Control Expires Set-Cookie;

        try_files $uri = 404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;

        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass unix:/run/php/php8.3-fpm.sock;
        fastcgi_index index.php;
    }

    # Кэшируем всю статику
    location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
        expires max;
    add_header Cache-Control "public";
    }

# Кэшируем js и css
    location ~* ^.+\.(css|js)$ {
    expires     1y;
    add_header Cache-Control "max-age=31600000, public";
    }
}


ngix.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
	worker_connections 768;
	multi_accept on;
	use epoll;
}

http {

	##
	# Basic Settings
	##

	sendfile on;
	tcp_nopush on;
	types_hash_max_size 900;
	# server_tokens off;

	# server_names_hash_bucket_size 64;
	# server_name_in_redirect off;

	include /etc/nginx/mime.types;
	default_type application/octet-stream;

	port_in_redirect off;
	keepalive_requests 100;

	client_body_buffer_size 10K;
	client_header_buffer_size 4k;    # на WordPress 2k может не хватать
	client_max_body_size 50m;
	large_client_header_buffers 2 4k;

	client_body_timeout 10;
	client_header_timeout 10;
	send_timeout 2;

	reset_timedout_connection on;
	tcp_nodelay on;

	fastcgi_read_timeout 300;

	open_file_cache max=10000 inactive=20s;
	open_file_cache_valid 30s;
	open_file_cache_min_uses 2;
	open_file_cache_errors on;

	fastcgi_cache_path /var/cache/nginx/fcgi levels=1:2 keys_zone=microcache:10m max_size=1024m inactive=1h;

	##
	# SSL Settings
	##

	ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
	ssl_prefer_server_ciphers on;
	ssl_stapling on;
	ssl_verify_depth 2;
	ssl_session_cache shared:SSL:5m;
	ssl_session_timeout 10m;
	ssl_dhparam /etc/nginx/dhparam-2048.pem;

	##
	# Logging Settings
	##

	error_log /var/log/nginx/error.log crit;    # только сообщения о критических ошибках
	access_log off;
	log_not_found off;

	##
	# Gzip Settings
	##

	gzip on;
	gzip_http_version 1.0;
	gzip_proxied any;
	gzip_min_length 1100;
	gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript image/svg+xml;
	gzip_disable msie6;
	gzip_vary on;



	##
	# Virtual Host Configs
	##

	include /etc/nginx/conf.d/*.conf;
	include /etc/nginx/sites-enabled/*;
}


#mail {
#	# See sample authentication script at:
#	# http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
#	# auth_http localhost/auth.php;
#	# pop3_capabilities "TOP" "USER";
#	# imap_capabilities "IMAP4rev1" "UIDPLUS";
#
#	server {
#		listen     localhost:110;
#		protocol   pop3;
#		proxy      on;
#	}
#
#	server {
#		listen     localhost:143;
#		protocol   imap;
#		proxy      on;
#	}
#}


wp-supercache.conf
# WP Super Cache rules.

set $cache true;

# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {
    set $cache false;
}

if ($query_string != "") {
    set $cache false;
}

# Don't cache uris containing the following segments
if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php
                      |wp-.*.php|/feed/|index.php|wp-comments-popup.php
                      |wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml
                      |[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
    set $cache false;
}

# Don't use the cache for logged-in users or recent commenters
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+
                     |wp-postpass|wordpress_logged_in") {
    set $cache false;
}

# Set the cache file
set $cachefile "/wp-content/cache/supercache/$http_host${request_uri}index.html";
set $gzipcachefile "/wp-content/cache/supercache/$http_host${request_uri}index.html.gz";

if ($https ~* "on") {
    set $cachefile "/wp-content/cache/supercache/$http_host${request_uri}index-https.html";
    set $gzipcachefile "/wp-content/cache/supercache/$http_host${request_uri}index-https.html.gz";
}

set $exists 'not exists';
if (-f $document_root$cachefile) {
    set $exists 'exists';
}

set $gzipexists 'not exists';
if (-f $document_root$gzipcachefile) {
    set $gzipexists 'exists';
}

if ($cache = false) {
    set $cachefile "";
    set $gzipcachefile "";
}

# Add cache file debug info as header
#add_header X-HTTP-Host $http_host;
add_header X-Cache-File $cachefile;
add_header X-Cache-File-Exists $exists;
add_header X-GZip-Cache-File $gzipcachefile;
add_header X-GZip-Cache-File-Exists $gzipexists;

#add_header X-Allow $allow;
#add_header X-HTTP-X-Forwarded-For $http_x_forwarded_for;
#add_header X-Real-IP $real_ip;

# Try in the following order: (1) gzipped cachefile, (2) cachefile, (3) normal url, (4) php
location / {
    try_files @gzipcachefile @cachefile $uri $uri/ /index.php?$args;
}

# Set expiration for gzipcachefile
location @gzipcachefile {
    expires 43200;
    add_header Cache-Control "max-age=43200, public";

    try_files $gzipcachefile =404;
}

# Set expiration for cachefile
location @cachefile {
    expires 43200;
    add_header Cache-Control "max-age=43200, public";

    try_files $cachefile =404;
}
  • Вопрос задан
  • 53 просмотра
Пригласить эксперта
Ответы на вопрос 1
@Bo3gyX
Для каждого сайта у вас должен быть отдельный конфиг в папке sites-enabled
например site1.conf, site2.conf, site3.conf
в каждом таком конфиге для каждого сайта должен быть указан домен сайта:
server_name site1.ru www.site1.ru;
и путь до корня root /home/web/site1.ru;
Подключение суперкеша закомментируйте на время настройки. Как только все сайты будут настроены и будут работать подключите конфиг суперкеша.
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы