2014-01-20 3 views
1

Я установил nginx, и я пытаюсь запустить wordpress на нем. Все работает нормально, за исключением постоянных ссылок.nginx & wordpress - настройка для постоянных ссылок не работает; загружает php-файлы вместо

Вот ВХост-файл, я использую:

server { 
listen 123456:80; 
server_name my-domain.com; 

if ($host ~* www\.(.*)) { 
    set $wwwless $1; 
    rewrite ^(.*)$ $scheme://$wwwless$1 permanent; 
} 

root /var/www/my-folder; 

index index.php; 

    location/{ 
      try_files $uri $uri/ /index.php?q=$uri&$args; 
    } 

    location ~ \.php$ { 
     fastcgi_split_path_info ^(.+\.php)(/.+)$; 
     fastcgi_pass unix:/var/run/php5-fpm.sock; 
     fastcgi_index index.php; 
     include fastcgi_params; 
    } 
} 

(я заменил критически важные данные в приведенном выше коде с my-domain.com, моей-папке и внутрибрюшинно 123456)

index.php, панель администратора и стандартные ссылки (... /? P = 123) работают finde. Если я включу некоторые постоянные ссылки, index.php и админ-панель будут работать. Но если я пытаюсь открыть еще один сайт WordPress блог, мой браузер загружает index.php :(

+0

Я мог бы частично исправить это, добавив следующее в местоположение ~ .php $ { fastcgi_param SCRIPT_FILENAME $ document_root/$ fastcgi_script_name; Теперь я могу получить доступ к другим сайтам блога. Но если я попытаюсь получить доступ к сообщению в блоге, например http://my-domain.com/1/hello-world/, я все равно получаю загрузку index.php. :/ – user3216381

+0

Обходной путь для последней проблемы заключался в использовании сборки в постоянных ссылках, а не в обычном. – user3216381

ответ

0

попробовать что-то вроде этого для .php расположения конфигурации:

location ~ \.php$ { 
    include  /etc/nginx/fastcgi_params; 
    fastcgi_pass 127.0.0.1:9000; 
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
} 
0

Вот мой WordPress конфигурации изменен, чтобы подхожу.

server { # the redirecting from www to non-www 
    server_name www.example.com; 
    return 301 $scheme://example.com$request_uri$is_args$query_string; 
} 

server { 
    listen 80; 
    server_name example.com; 
    root /path/to/root; 
    # make sure the directory /var/log/nginx exists 
    access_log /var/log/nginx/wordpress_access.log; 
    error_log /var/log/nginx/wordpress_error.log; 
    index index.php; 
    location/{ 
    try_files $uri /index.php$request_uri$is_args$query_string; 
    } 
    location ~ \.php { 
    include fastcgi_params; 
    fastcgi_pass unix:/var/run/php5-fpm.sock; 
    } 
    location ~ /\.ht { # avoid downloading htaccess, htpasswd, etc files 
    deny all; 
    } 
} 
0

вы можете попробовать этот файл виртуального хоста

server { 
    listen 80; 
    server_name www.example.com example.com; 
    root /var/www/www.example.com/web; 
    if ($http_host != "www.example.com") { 
      rewrite^http://www.example.com$request_uri permanent; 
    } 
    index index.php index.html; 
    location = /favicon.ico { 
      log_not_found off; 
      access_log off; 
    } 
    location = /robots.txt { 
      allow all; 
      log_not_found off; 
      access_log off; 
    } 
    # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac). 
    location ~ /\. { 
      deny all; 
      access_log off; 
      log_not_found off; 
    } 
    location/{ 
      try_files $uri $uri/ /index.php?$args; 
    } 
    # Add trailing slash to */wp-admin requests. 
    rewrite /wp-admin$ $scheme://$host$uri/ permanent; 
    location ~* \.(jpg|jpeg|png|gif|css|js|ico)$ { 
      expires max; 
      log_not_found off; 
    } 
    location ~ \.php$ { 
      try_files $uri =404; 
      include /etc/nginx/fastcgi_params; 
      fastcgi_pass 127.0.0.1:9000; 
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    } 

}

Смежные вопросы