我正在尝试在 Nginx + HVVM 上运行 Wordpress。它在 Apache + PHP 上运行良好,但是当我激活 Nginx 时,网站中的大多数 URL 都会被重写为 https。
这是我的网站配置:
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
页面源代码中的所有 URL 都输出为 https://,这完全是错误的:该网站没有 https 版本。
我不知道该看哪里。日志中没有错误,无论是 Nginx 还是 HHVM。而且配置对我来说看起来没问题。
编辑:
我现在在端口 8080 上运行 nginx + HHVM 进行测试,同样的事情发生了,而且更糟。如果我去http://www.claremacdonald.co.uk:8080,我被重定向到https://www.claremacdonald.co.uk,但它并不存在。
这是输出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
显然,nginx 正在使用 301 将我重定向到 https,但我看不到任何地方配置它。
答案1
有一次我配置 VirtualHosts 时遇到过这种情况,你的浏览器(我确定是 Firefox)会保存网站偏好设置。如果你曾经使用 https 加载过网站,它会保存它,并在你加载后继续使用 https 加载。使用 CTRL+SHIFT+DEL 清除网站缓存和偏好设置,如果有帮助