Nginx not redirecting to https

时间:2018-01-23 19:36:02

标签: nginx https reverse-proxy

I have a problem with http requests with my Nginx configuration.

server {
  listen 80;
  listen [::]:80;
  server_name www.queroemprego.pt queroemprego.pt;
  return 301 https://www.queroemprego.pt$request_uri;
}

server {
  listen 443 ssl;
  listen [::]:443 ssl;
  server_name queroemprego.pt;
  return 301 https://www.queroemprego.pt$request_uri;

  ssl on;
  {...}
}

server {
  listen 443 ssl;
  listen [::]:443 ssl;
  server_name www.queroemprego.pt;
  {...}
}

Nginx is listening to both ports and my iptables looks okay

tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      0          4204048    12064/nginx: master 
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      0          4204050    12064/nginx: master 

https requests are working and accessing it via https://www.queroemprego.pt should work and has been working for the past month. But I noticed that http requests are failing for some people and I have no idea why. The following page tries to get the http version and the requests fails. http://downforeveryoneorjustme.com/queroemprego.pt

I have 2 more subdomains with similar configurations, redirecting http to https. Any ideas?

Edit: Here are my iptables

iptables --list
Chain INPUT (policy DROP)
target     prot opt source               destination         
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere             state RELATED,ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:ssh
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:https
ACCEPT     tcp  --  localhost            anywhere             tcp dpt:smtp

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination   

1 个答案:

答案 0 :(得分:3)

所以,问题在于我的iptables。 我虽然接受了80端口的请求,但是没有。 这是解决方案:

iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT