Подтвердить что ты не робот

Nginx - wordpress в подкаталоге, какие данные должны быть переданы?

Я пробовал так много разных вещей. Дело в том, что я сейчас:

location ^~ /wordpress {
    alias /var/www/example.com/wordpress;
    index index.php index.html index.htm;
    try_files $uri $uri/ /wordpress/index.php;

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_split_path_info ^(/wordpress)(/.*)$;
        fastcgi_param SCRIPT_FILENAME /var/www/example.com/wordpress/index.php;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

В настоящий момент все ресурсы, насколько я могу судить (изображения и т.д.), загружаются правильно. И http://www.example.com/wordpress загружает wordpress, но страницу, в которой говорится, что "страница не найдена". (Wordpress используется для этого, хотя). Если я попытаюсь использовать любые почтовые URL-адреса, я получаю тот же результат, "страница не найдена". Поэтому я знаю, что проблема заключается в том, что wordpress не получает данные о пути или что-то в этом роде. Другая потенциальная проблема заключается в том, что если я запустил example.com/wp-admin.php, то он все равно будет работать index.php.

Какие данные необходимо передать? Что здесь может быть неправильным?

4b9b3361

Ответ 1

Так как ваше совпадение в конце адреса местоположения, вы должны просто использовать root. Кроме того, не все направлено через index.php на wordpress afaik. Кроме того, если вы не знаете, что вам нужна информация о пути, вероятно, нет. Я думаю, вам нужно что-то вроде:

location @wp {
  rewrite ^/wordpress(.*) /wordpress/index.php?q=$1;
}

location ^~ /wordpress {
    root /var/www/example.com;
    index index.php index.html index.htm;
    try_files $uri $uri/ @wp;

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        fastcgi_pass 127.0.0.1:9000;
    }
}

или если вам действительно нужна информация о пути (URL-адреса выглядят как /wordpress/index.php/foo/bar):

location ^~ /wordpress {
    root /var/www/example.com;
    index index.php index.html index.htm;
    try_files $uri $uri/ /wordpress/index.php;

    location ~ \.php {
        fastcgi_split_path_info ^(.*\.php)(.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_pass 127.0.0.1:9000;
    }
}

EDIT: обновлен первый сервер {}, чтобы удалить начальный /wordpress из uri и оставить остаток в виде q param

EDIT2: Именованные местоположения действительны только на уровне сервера

Ответ 2

Чувак, это будет работать для блога wordpress в подкаталоге корневой папки magento!

server {
listen 80;
server_name my-site.co.uk;
rewrite / $scheme://www.$host$request_uri permanent; ## Forcibly prepend a www
}

server {
listen 80 default;
client_max_body_size 8M;
## SSL directives might go here
server_name www.my-site.co.uk; ## Domain is here twice so server_name_in_redirect will favour the www
root /var/www/my-site/magento;

location / {
    index index.html index.php; ## Allow a static html file to be shown first
   try_files $uri $uri/ @handler; ## If missing pass the URI to Magento front handler
   expires 30d; ## Assume all files are cachable
}

location  /wordpress {
          index index.php index.html index.htm;
         try_files $uri $uri/ /wordpress/index.php;
         }

## These locations would be hidden by .htaccess normally
location ^~ /app/                { deny all; }
location ^~ /includes/           { deny all; }
location ^~ /lib/                { deny all; }
location ^~ /media/downloadable/ { deny all; }
location ^~ /pkginfo/            { deny all; }
location ^~ /report/config.xml   { deny all; }
location ^~ /var/                { deny all; }

location /var/export/ { ## Allow admins only to view export folder
    auth_basic           "Restricted"; ## Message shown in login window
    auth_basic_user_file htpasswd; ## See /etc/nginx/htpassword
    autoindex            on;
}

location  /. { ## Disable .htaccess and other hidden files
    return 404;
}


location @handler { ## Magento uses a common front handler
    rewrite / /index.php;
}

location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
    rewrite ^(.*.php)/ $1 last;
}

location ~ .php$ { ## Execute PHP скриптs
    if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss

    expires        off; ## Do not cache dynamic content
    fastcgi_pass   unix:/var/run/php5-fpm.sock;
    fastcgi_param  HTTPS $fastcgi_https;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    fastcgi_param  MAGE_RUN_CODE default; ## Store code is defined in administration > Configuration > Manage Stores
    fastcgi_param  MAGE_RUN_TYPE store;
    include        fastcgi_params; ## See /etc/nginx/fastcgi_params
}

}

Ответ 3

У меня была такая же проблема, и это было исправлено для меня:

  • Откройте файл конфигурации NGINX для вашего сайта. Внутри блока сервера добавьте путь к корневому каталогу и установите порядок приоритета для файлов:

    root /mnt/www/www.domainname.com;
    index  index.php index.html index.htm;
    
  • Создайте пустой блок местоположения перед всеми вашими другими блоками местоположения:

    location /latest {
    # Nothing in here; this is to avoid redirecting for this location
    }
    
  • Отметьте корневой каталог в вашем местоположении/блоке и добавьте перенаправление, чтобы оно выглядело следующим образом:

    location / {
    # root   /mnt/www/www.domainname.com;
    index  index.php index.html index.htm;
    rewrite ^/(.*)$ http://www.domainname.com/latest/$1 redirect;
    }
    
  • Убедитесь, что ваш блок ~.php $указывает ваш корень на

    root /mnt/www/www.domainname.com;
    

Это исправило это для меня.