Craft Version: 3.0.4
Web Server: Apache + Nginx proxy

Recently I've been working on a couple of Craft 3 projects for deployment on my institution's web servers. In the past, I've successfully launched numerous Craft 2 projects without server-specific issues, save for needing to set the Apache HTTP_ACCEPT header as follows in .htaccess (because it wasn't already configured by httpd.conf):

SetEnv HTTP_ACCEPT text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

On my initial attempts to deploy Craft 3 to the same servers (and using the same HTTP_ACCEPT configuration in .htaccess), I ran into odd behavior when trying to log in: initially the login process would fail silently (i.e. submitting username/password would process but remain on the login page), but if I were to then immediately refresh the login page a logged-in session would be established and Craft would load the CP.

Once the CP loaded, Craft would throw an error ("An unknown error occurred") and subsequent attempts to navigate through the CP would throw the same error and content such as lists of entries would not appear. Further investigation of network request showed that /actions (POST, GET) requests were failing with 400 Bad Request, with a response of "Request must accept JSON in response".

Initially, before I happened upon actual bad request response details, the folks at Craft thought the issue might pertain to an inconsistent use of HTTPS, or something specific to the use of the Nginx proxy server.

As a test, however, I added application/json to the HTTP_ACCEPT header as follows:

SetEnv HTTP_ACCEPT text/html,application/xhtml+xml,application/xml,application/json;q=0.9,*/*;q=0.8

Low and behold, I was then able to successfully log in and navigate the CP. All of the POST and GET requests to /actions responded successfully.

Now, however, I've ended up in spot where saving an entry successfully commits the change to the database but renders the raw JSON response of the POST request on the page rather than returning to the entry's edit page. Here's an example of what I see in the browser when saving an entry:


The url in the browser remains on the entry such that if I refresh the page, I'm returned to the entry in the CP and see the updated content.

At this point, I'm stuck and not sure if the HTTP_ACCEPT header is configured incorrectly, or if the Nginx proxy server is indeed interfering with the requests.

Many thanks in advance for thoughts/assistance.

1 Answer 1


IMO, the issue is with this line.

SetEnv HTTP_ACCEPT text/html,application/xhtml+xml,application/xml,application/json;q=0.9,*/*;q=0.8

With ACCEPT headers set to a fixed value, it's impossible for Craft 3 to distinguish between Json and HTML requests. This must have been a necessity with the nginx proxy setup.

I suggest removing this line from Apache and configure nginx to pass through the original request headers.

If you use proxy_pass, trying adding this line

location / {
    proxy_pass_request_headers on;

OR, if you prefer a more direct approach

location / {
    proxy_set_header Accept $http_accept;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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