1

Has anyone had success with using Craft and WTServer (WinNMP) together? I'm getting a 400 error at "http://craft.test/index.php?p=admintrigger/actions/users/login" after trying to login the admin. I'm suspicious that my Nginx config rewrites aren't working, but unsure how to troubleshoot it. The front-end displays fine, and the login screen works but the login submit throws the 400 error.

nginx server block...

server {

listen      127.0.0.1:80;
server_name     craft.test craft.dev;
charset utf-8;
root    "c:/wtserver/www/craft/web"; # locked
allow       127.0.0.1;
deny        all;
index index.html index.htm index.php;
ssi on;
client_max_body_size 0;
error_page 404 /index.php?$query_string;

location / {
    try_files $uri/index.html $uri $uri/ /index.php?$query_string;
}

location ~ [^/]\.php(/|$) {
    try_files $uri $uri/ /index.php?$query_string;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    # Change this to whatever version of php you are using
    include     nginx.fastcgi.conf;
    include     nginx.redis.conf;
    fastcgi_pass    php_farm;
    fastcgi_hide_header X-Powered-By;

    add_header Last-Modified $date_gmt;
    add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0";
    if_modified_since off;
    expires off;
    etag off;

    fastcgi_intercept_errors off;
    fastcgi_buffer_size 16k;
    fastcgi_buffers 4 16k;
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
}

location ~ /\.(ht|svn|git) {
    deny all;
}

sendfile off;

general.php

return [
// Global settings
'*' => [
    // Default Week Start Day (0 = Sunday, 1 = Monday...)
    'defaultWeekStartDay' => 1,

    // Whether generated URLs should omit "index.php"
    'omitScriptNameInUrls' => true,

    // Control Panel trigger word
    'cpTrigger' => 'admintrigger',

    // The secure key Craft will use for hashing and encrypting data
    'securityKey' => getenv('SECURITY_KEY'),

    // Whether to save the project config out to config/project.yaml
    // (see https://docs.craftcms.com/v3/project-config.html)
    'useProjectConfigFile' => false,
],

// Dev environment settings
'dev' => [
    // Dev Mode (see https://craftcms.com/guides/what-dev-mode-does)
    'devMode' => true,
],

// Staging environment settings
'staging' => [
    // Set this to `false` to prevent administrative changes from being made on staging
    'allowAdminChanges' => true,
],

// Production environment settings
'production' => [
    // Set this to `false` to prevent administrative changes from being made on production
    'allowAdminChanges' => true,
],

Error in the Network console...

enter image description here

404s...

2019-04-07 10:54:44 [-][-][dc567ad367247e3bf37e7ce11ac60e93][error][yii\web\HttpException:404] yii\web\NotFoundHttpException: Template not found: favicon.ico in C:\WinNMP\WWW\craft\vendor\craftcms\cms\src\controllers\TemplatesController.php:70 Stack trace: 0 [internal function]: craft\controllers\TemplatesController->actionRender('favicon.ico', Array) 1 C:\WinNMP\WWW\craft\vendor\yiisoft\yii2\base\InlineAction.php(57): call_user_func_array(Array, Array) 2 C:\WinNMP\WWW\craft\vendor\yiisoft\yii2\base\Controller.php(157): yii\base\InlineAction->runWithParams(Array) 3 C:\WinNMP\WWW\craft\vendor\craftcms\cms\src\web\Controller.php(109): yii\base\Controller->runAction('render', Array) 4 C:\WinNMP\WWW\craft\vendor\yiisoft\yii2\base\Module.php(528): craft\web\Controller->runAction('render', Array) 5 C:\WinNMP\WWW\craft\vendor\craftcms\cms\src\web\Application.php(297): yii\base\Module->runAction('templates/rende...', Array) 6 C:\WinNMP\WWW\craft\vendor\yiisoft\yii2\web\Application.php(103): craft\web\Application->runAction('templates/rende...', Array) 7 C:\WinNMP\WWW\craft\vendor\craftcms\cms\src\web\Application.php(286): yii\web\Application->handleRequest(Object(craft\web\Request)) 8 C:\WinNMP\WWW\craft\vendor\yiisoft\yii2\base\Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request)) 9 C:\WinNMP\WWW\craft\web\index.php(21): yii\base\Application->run() 10 {main}

0

For me, this didn't have anything to do with rewrites. I installed WTServer (WinNMP) and a fresh copy of Craft.

I noticed the same 400 response when trying to log in and was seeing this in the body:

400 Request Header Or Cookie Too Large

After a quick Google, I noticed that the default nginx config that WTServer has these set:

client_header_buffer_size   1k;
large_client_header_buffers 2 1k;

I bumped those up to this:

client_header_buffer_size   8k;
large_client_header_buffers 8 16k;

Restarted nginx and everything started working fine.

  • Boom! Thanks so much Brad. Huge Craft points. You just made me more willing to dive in. – Jim Apr 12 at 15:15
1

This is my clean wtserver/winnmp nginx conf file for Craft (and pretty much anything else like Laravel etc.).

server {

    listen          127.0.0.1:80;
    server_name     icraft.test; # locked
    root            "c:\web\icraft\public"; # locked

    allow           127.0.0.1;
    deny            all;
    autoindex       on;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        try_files $uri =404;
        include         nginx.fastcgi.conf;
        include         nginx.redis.conf;
        fastcgi_pass    php_farm;
    }

}

Assuming you installed winnmp to c:\web\winnmp, this file would go to c:\web\winnmp\conf\domains.d\icraft.conf

You can drop the index.php?p= part (just use pretty URLs) - if you're still having issues, post your config\general.php, you might have a Craft config issue.

  • Thanks! I've looked at general.php but didn't make any changes. I've included it above. Even with omitScriptNameInUrls set to true, the login submit is still looking for index.php with args. Still having trouble logging in. I've simplified my server block to the essentials. – Jim Mar 31 at 19:15
  • It could be a PHP ini setting - sounds like Craft cannot recognize that your server supports pretty paths. I would suggest you start with a clean Winnmp install (latest version 19.03 as of yesterday) and then go into \winnmp\conf\php.ini and add at least these changes: open_basedir = none ; disable_functions... ... and check in Craft CP that it's happy with all server settings in admin//utilities/system-report – Jure Srpcic Apr 1 at 7:52
  • And I'd suggest you just start with a completely clean craft install - docs.craftcms.com/v3/installation.html - it works out of the box without any changes to any config using WinNmp - so you'll know the issue isn't in a config setting etc. – Jure Srpcic Apr 1 at 7:57
  • Thanks for you help. This isn't working for me yet. I've started with clean installs of both WinNMP and Craft, but the login submission is still looking for craft.test/index.php?p=maker/actions/users/login in the path. So Craft isn't able to find a template. I've also made the changes to the php.ini. Any other thoughts? – Jim Apr 7 at 17:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.