eaayoata
eaayoata

Reputation: 5

Nginx - allow HTTP for IP

I have a configuration that will not allow any HTTP calls to my service (forcing https). I need to provide HTTP access to only one IP and I am not sure what is the best way to do that or if it's possible to do that with NGINX.

Here is my configuration:

    server {
        listen 80;
        listen 443;
        server_name myserver.com;

        client_max_body_size 64M;
        proxy_connect_timeout       600;
        proxy_send_timeout          600;
        proxy_read_timeout          600;
        send_timeout                600;

        ssl on;
        ssl_certificate /com.crt;
        ssl_certificate_key /com.key;

        access_log /var/log/nginx/log.log custom;

        if ($scheme = http) {
                return 400  "Sceme not allowed - please use https (SSL)";
        }

        location / {
                include proxy_params;
                proxy_pass http://unix:/tmp/my.sock:/;
                add_header Cache-Control private;
        }

        location /static/ {
                root /var/www/myapp/root;
        }
}

Upvotes: 0

Views: 6449

Answers (1)

Richard Smith
Richard Smith

Reputation: 49702

You have SSL enabled for port 80. You should use the ssl parameter on the listen directive and remove the ssl on; statement:

listen 80;
listen 443 ssl;

This allows non-SSL to port 80 and SSL to port 443.

See this document for details.

Upvotes: 1

Related Questions