2

I am trying to run Wordpress on Nginx + HVVM. It runs fine on Apache + PHP, but when I activate Nginx, most of the urls in the website get rewritten to https.

Here is my website config:

server {

    root /var/www/claremacdonald.co.uk;
    index index.php index.html index.htm;

    server_name *.claremacdonald.co.uk;
    include hhvm.conf;

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

}

hhvm.conf:

location ~ \.(hh|php)$ {
    fastcgi_keep_conn on;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

/etc/hhvm/server.ini

; php options

pid = /var/run/hhvm/pid

; hhvm specific 

hhvm.server.port = 9000
hhvm.server.type = fastcgi
hhvm.server.default_document = index.php
hhvm.log.use_log_file = true
hhvm.log.file = /var/log/hhvm/error.log
hhvm.repo.central.path = /var/run/hhvm/hhvm.hhbc

/etc/hhvm/php.ini

; php options
session.save_handler = files
session.save_path = /var/lib/php5
session.gc_maxlifetime = 1440

; hhvm specific 
hhvm.log.level = Warning
hhvm.log.always_log_unhandled_exceptions = true
hhvm.log.runtime_error_reporting_level = 8191
hhvm.mysql.typed_results = false
hhvm.mysql.socket = /var/run/mysqld/mysqld.sock

All of the urls in the page source are output as https:// which is simply wrong: there is no https version of the site.

I'm not sure where to look. There are no errors in the logs, either of Nginx or HHVM. And the configuration looks ok to me.

EDIT:

I now have nginx + HHVM running on port 8080 to test, and the same thing is happening, only worse. If I go to http://www.claremacdonald.co.uk:8080, I get redirected to https://www.claremacdonald.co.uk, which does not exist.

This is the output from curl -v http://www.claremacdonald.co.uk:8080

* Rebuilt URL to: http://www.claremacdonald.co.uk:8080/
*   Trying 78.47.105.5...
* Connected to www.claremacdonald.co.uk (78.47.105.5) port 8080 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.41.0
> Host: www.claremacdonald.co.uk:8080
> Accept: */*
> 
< HTTP/1.1 301 Moved Permanently
< Server: nginx/1.2.1
< Date: Mon, 23 Mar 2015 09:35:43 GMT
< Content-Type: text/html; charset=UTF-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< Set-Cookie: PHPSESSID=**********************; path=/
< Expires: Thu, 19 Nov 1981 08:52:00 GMT
< Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
< X-Pingback: https://www.claremacdonald.co.uk/xmlrpc.php
< X-Powered-By: HHVM/3.6.0
< Pragma: no-cache
< Location: https://www.claremacdonald.co.uk/
< 
* Connection #0 to host www.claremacdonald.co.uk left intact

Apparently nginx is redirecting me to https with a 301, but I can't see it configured anywhere.

  • I don't see anything in this configuration that would do that. Have you got any other nginx configuration files? Have you checked to ensure that the home and siteurl are correct in WordPress? – Michael Hampton Mar 21 '15 at 15:06
  • Yup! And it works perfectly under Apache. – Tom Macdonald Mar 21 '15 at 15:07
  • Sorry, I neglected to reply to your first question. There are no other nginx configuration files I know of. I basically did apt-get install nginx and configured the virtualhost. – Tom Macdonald Mar 21 '15 at 19:40
  • Strange, when I visited your site I was not redirected to https. Are you sure you're actually still having a problem? Did you clear your browser cache? – Michael Hampton Mar 21 '15 at 19:43
  • Lol that's not actually the website. I just was using that as an example. I'll update to something else. In any case the actual website is currently running on Apache + mod_php which works perfectly. – Tom Macdonald Mar 21 '15 at 20:55
0

This once happened to me when I was configuring my VirtualHosts, your browsers (Firefox am sure of) saves site preferences. If you once loaded the site with https it saves it and keep loading with https once you load it. Clear site cache and preferences with CTRL+SHIFT+DEL and if it helps

  • This is definitely server-side. It even happens when using cURL. – Tom Macdonald Mar 23 '15 at 9:51
  • am not a Nginx fan though but why using regex in server_name Better still try server_name claremacdonald.co.uk www.claremacdonald.co.uk Let's see next step – Jajo Mar 23 '15 at 13:25
  • Did not work unfortunately. – Tom Macdonald Mar 23 '15 at 13:32
  • 1
    Ok I found it: in /etc/nginx/fastcgi_params, I needed to set fastcgi_param HTTPS to off and not $https – Tom Macdonald Mar 23 '15 at 13:46
  • Glad to see this solved and I learnt too :) (y) – Jajo Mar 23 '15 at 13:48

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.