nginx配置及HTTPS配置示例

一、nginx简单配置示例

user  www www;

worker_processes 10;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

#最大文件描述符
worker_rlimit_nofile 51200;

events
{
      use epoll;
      worker_connections 51200;
}

http
{
      include       conf/mime.types;
      default_type  application/octet-stream;

      keepalive_timeout 120;

      tcp_nodelay on;

      upstream  www.xxx.com  {
              server   192.168.1.2:80;
              server   192.168.1.3:80;
              server   192.168.1.4:80;
              server   192.168.1.5:80;
      }

      upstream  blog.xxx.com  {
              server   192.168.1.7:8080;
              server   192.168.1.7:8081;
              server   192.168.1.7:8082;
      }

      server
      {
              listen  80;
              server_name  www.xxx.com;

              location / {
                       proxy_pass        http://www.zyan.cc;
                       proxy_set_header   Host             $host;
                       proxy_set_header   X-Real-IP        $remote_addr;
                       proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
                       proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504 http_404;
              }

              log_format  www_xxx_com  ‘$remote_addr - $remote_user [$time_local] $request ‘
                                ‘"$status" $body_bytes_sent "$http_referer" ‘
                                ‘"$http_user_agent" "$http_x_forwarded_for"‘;
              access_log  /data1/logs/www.log  www_xxx_com;
      }

      server
      {
              listen  80;
              server_name  blog.xxx.com;

              location / {
                       proxy_pass        http://blog.zyan.cc;
                       proxy_set_header   Host             $host;
                       proxy_set_header   X-Real-IP        $remote_addr;
                       proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
                       proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504 http_404;
              }

              log_format  blog_xxx_com  ‘$remote_addr - $remote_user [$time_local] $request ‘
                                ‘"$status" $body_bytes_sent "$http_referer" ‘
                                ‘"$http_user_agent" "$http_x_forwarded_for"‘;
              access_log  /data1/logs/blog.log  blog_xxx_com;
      }
}

二、HTTPS配置示例

upstream  xxx_xxx_xxx  {
    server   192.168.1.7:8080;
    server   192.168.1.7:8081;
    server   192.168.1.7:8082;
}
server {
    listen 443;

    server_name xxx.xxx.xxx;

    access_log /home/chenwebstore1/logs/xxx.xxx.xxx/https.29289080/access.log combined;
    error_log /home/chenwebstore1/logs/xxx.xxx.xxx/https.29289080/error.log error;

    ssl on;
    ssl_certificate keys/xxx.xxx.xxx.pem;
    ssl_certificate_key keys/xxx.xxx.xxx.key;
    ssl_session_cache shared:ssl.xxx.xxx.xxx:128k;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

    location / {
        proxy_pass        http://xxx_xxx_xxx;
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504 http_404;
    }
}

其中ssl_certificate_key文件格式为:

-----BEGIN RSA PRIVATE KEY-----
-----END RSA PRIVATE KEY-----

其中ssl_certificate文件格式(后缀可以为cer)为:

(Certificate:)
----BEGIN CERTIFICATE-----
----END CERTIFICATE-----
(Intermediate Certificate:)
-----BEGIN CERTIFICATE-----
-----END CERTIFICATE-----

上面这三段字符串值可以在HTTPS证书申请时获取到。

时间: 2024-08-01 15:16:06

nginx配置及HTTPS配置示例的相关文章

Nginx HA 及https配置部署

Nginx HA 整体方案架构为: (内网192.168.199.5) +-----------VIP----------+ | | | | Master Backup 192.168.199.90 192.168.199.57 +----------+ +----------+ | HAProxy | | HAProxy | |nginx(SSL)| |nginx(SSL)| |keepalived| |keepalived| +----------+ +----------+ | v 192

nginx普通配置/负载均衡配置/ssl/https配置

1.nginx普通配置 server { listen 80; server_name jqlin.lynch.com; access_log /var/log/nginx/main.log main; error_log /var/log/nginx/pay_local.error; #log_format access '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent $re

nginx http跳https配置

为了数据传输的安全性以及防止网页被恶意篡改,现在大多数网站都配置了https. 如何保证用户都是通过https进行访问呢? 如果有用到nginx,我们可以配置强制跳转. 在nginx配置中添加: server { listen 80; listen 443 ssl; server_name www.imcati.com; root /usr/share/nginx/html; if ( $server_port = 80) { return 301 https://$server_name$re

Linux学习总结(四十三)nginx 负载均衡 https 配置

1 nginx 负载均衡 当被代理的服务端为多台服务器时,就存在一个分发的问题,那么就涉及到一个负载均衡的概念.如何让客户端请求按照预定的设想均衡的分发到各个服务器上,就要使用各种均衡算法.下面介绍的ip哈希算法可以实现如下目的.当对后端的多台动态应用服务器做负载均衡时,ip_hash指令能够将某个客户端IP的请求通过哈希算法定位到同一台后端服务器上.这样,当来自某个IP的用户在后端Web服务器A上登录后,再访问该站点的其他URL,能够保证其访问的还是后端Web服务器A.如果请求的网站涉及到用户

nginx基本用法和HTTPS配置

nginx作用讲解:1.反向代理:需要多个程序共享80端口的时候就需要用到反向代理,nginx是反向代理的一种实现方式.2.静态资源管理:一般使用nginx做反向代理的同时,应该把静态资源交由nginx管理.3.负载均衡:略. nginx原理:nginx实质是通过配置文件创建监听80端口的服务器,然后通过该服务器重定向请求到指定端口. nginx实现HTTPS访问:原理同上文,使用配置文件创建HTTPS服务器,然后通过该服务器重定向请求到指定端口. 为什么要用nginx管理静态资源?1.减少了重

为微信小程序开发做准备,在Centos 6.8下利用letsencrypt.sh脚本为nginx 配置免费https证书

原文链接: http://phpecshop.blog.51cto.com/6296699/1891737 最近在做微信小程序商城开发的时候,阅读官方api文档发现要求https,的路程. wx.request(OBJECT) wx.request发起的是 HTTPS 请求. 于是开始了在Centos 6.8下利用letsencrypt.sh脚本为nginx 配置免费https(Let's Encrypt SSL证书) 1.下载letsencrypt.sh # wget https://raw.

Nginx 学习笔记(一)个人网站的Https配置

一.系统环境 1.系统:Ubuntu 16.04.2 LTS 2.WEB服务器:Openresty11.2.5 二.开始配置 1.获取certbot客户端 wget https://dl.eff.org/certbot-auto chmod a+x certbot-auto 2.停止Nginx服务 sudo systemctl stop nginx.service 3.生成证书 ./certbot-auto certonly --standalone --email `你的邮箱地址` -d `你

nginx证书制作以及配置https并设置访问http自动跳转https(反向代理转发jboss)

nginx证书制作以及配置https并设置访问http自动跳转https 默认情况下ssl模块并未被安装,如果要使用该模块则需要在编译时指定–with-http_ssl_module参数,安装模块依赖于OpenSSL库和一些引用文件,通常这些文件并不在同一个软件包中.通常这个文件名类似libssl-dev. 生成证书 可以通过以下步骤生成一个简单的证书: 首先,进入你想创建证书和私钥的目录,例如: $ cd /usr/local/nginx/conf 创建服务器私钥,命令会让你输入一个口令: $

Tengine(Nginx)配置SSL(https),应用服务器(Tomcat)无需配置

要点:如果系统是内部用,可以通过openssl生成证书,只是访问的时候,浏览器会提示不信任, 1.生成证书,创建存放证书的目录/home/sslkey,并进入该目录,输入如下命令,按照提示填写相关的注册信息,完成后,会生成web.key.web.csr.web.key.org.web.crt这几个文件 openssl genrsa -des3 -out web.key 2048 openssl req -new -key web.key -out web.csr cp web.key web.k