---
title: "nginx强制https 重定向所有http请求到https"
author: "tinyhema"
date: "2018-09-21T00:35:22Z"
tags: []
categories: ["开源软件"]
slug: "nginx-https-http-https"
draft: false
lastmod: "2018-09-21T00:35:22Z"
id: 2431074
url: "https://tinyhema.iteye.com/blog/2431074"
---

nginx重定向所有http请求到https


```shell

# vi sub.domain.conf
server{
    listen 80;

    server_name sub.domain.com;
    return 301 https://$host$request_uri;
}

server{
    charset utf-8;

    listen 443 ssl;
    ssl on;
    ssl_certificate /usr/local/nginx/conf/cert/sub.domain.com.crt;
    ssl_certificate_key /usr/local/nginx/conf/cert/sub.domain.com.key;
    server_name sub.domain.com;

    auth_basic "auth";
    auth_basic_user_file /usr/local/nginx/conf/cert/pass_file;

    access_log  /home/wwwlogs/sub.domain.com.log;
    error_log /home/wwwlogs/sub.domain.com.err;

    location / {
        proxy_pass http://127.0.0.1:99999;
    }
}

```