• Nginx 安装学习笔记(1.安装和启动 2.https模块安装 3.负载均衡/反向代理)


    centos7 编译安装和启动.停止https://www.cnblogs.com/xingyunblog/p/9072553.html
    1.安装和启动
    一.安装nginx
    1.下载 wget http://nginx.org/download/nginx-1.9.15.tar.gz,安装 四个依赖库 yum -y install gcc gcc-c++ make zlib-devel pcre-devel openssl-devel
    2.解压 tar -zxvf nginx.tar.gz
    3./configure [--prefix] 配置可以指定安装路径 报错的话,需要安装几个包 yum -y install gcc gcc-c++ make zlib-devel pcre-devel openssl-devel
    4.make 编译
    5 make install 安装 (注意,安装和编译的命令是在安装的路径下,它会默认安装和编译到第三步--prefix指定的目录下)
    二.启动和停止
    1.进入到nginx安装的路径(--prefix指定的目录)
    2.进入到sbin目录
    3.启动 ./nginx
    4.关闭 ./nginx -s stop
    5.修改配置后重新加载 、或重启(nginx没有关闭) ./nginx -s reload

    2.https 模块安装
    1 需要安装https模块 ,执行 命令 ./configure --prefix=/home/software/nginx/nginxlocation --with-http_stub_status_module --with-http_ssl_module
    2. 执行编译命令 make
    3. 执行安装命令 make install
    4. 去安装路径sbin下启动 ./nginx

    3.负载均衡/反向代理
    1.配置upstream 即可

    upstream myProxy {
     ip_hash;
         server 127.0.0.1:8080; 
     server 127.0.0.1:80; 
      }
    
    server {
        listen       80;
        server_name  jinjian.*;
        access_log  logs/host.access.log  main;
        location / {
        proxy_pass http://myProxy;
        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 http_502 http_504 error timeout invalid_header; 
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    
    server {
        listen       8080;
        server_name  jinjian.*;
        access_log  logs/host.access.log  main;
        location / {
        proxy_pass http://myProxy;
        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 http_502 http_504 error timeout invalid_header; 
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    
    #https配置
    server {
       listen       443 ssl;
       server_name  localhost;
       #开启  如果把ssl on;这行去掉,ssl写在443端口后面。这样http和https的链接都可以用
       #ssl on;
    
       ssl_certificate      /home/software/nginx/httpscert/Nginx/1_jinjian.xyz_bundle.crt;
       ssl_certificate_key  /home/software/nginx/httpscert/Nginx/2_jinjian.xyz.key;
    
       ssl_session_cache    shared:SSL:1m;
       ssl_session_timeout  5m;
    
       ssl_ciphers  HIGH:!aNULL:!MD5;
       ssl_prefer_server_ciphers  on;
     }
    

    80端口 https访问其他路径
    server {
    listen 80;
    rewrite ^/(.*) https://$server_name$request_uri?permanent;
    }

    server {
       listen 443 ssl;
        server_name  jinjian.xyz;
    #开启  如果把ssl on;这行去掉,ssl写在443端口后面。这样http和https的链接都可以用
         ssl on;
    
        ssl_certificate      /home/software/nginx/httpscert/Nginx/1_jinjian.xyz_bundle.crt;
        ssl_certificate_key  /home/software/nginx/httpscert/Nginx/2_jinjian.xyz.key;
    
       ssl_session_cache    shared:SSL:1m;
       ssl_session_timeout  5m;
       ssl_ciphers  HIGH:!aNULL:!MD5;
       ssl_prefer_server_ciphers  on;
    	
        location / {
            root   html;
            index  index.html index.htm;
        }
     location /api { 
                proxy_pass      https://myProxy;
                proxy_redirect off;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    

    }

    esay!!

  • 相关阅读:
    求长度的另一种方法(""+obj).Length
    XCode中如何使用事务
    最终版 Reflector v1.0 (+简单的反流程混淆)
    与ObjectDataSource共舞
    性能&分布式&NewLife.XCode对无限数据的支持
    XCode之第一次亲密接触
    5,ORM组件XCode(动手)
    你知道吗?多个类多线程环境下静态构造函数的执行顺序
    使用C#编写IDA插件 IDACSharp v1.0.2010.0605
    XCMS V1.0 Beta1 发布
  • 原文地址:https://www.cnblogs.com/jinjian91/p/10520625.html
Copyright © 2020-2023  润新知