栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

nginx 配置及解读

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

nginx 配置及解读

listen 80; 监听端口 
server_name www.abc.com abc.com; 域名可以有多个,用空格隔开 
charset koi8-r; 编码集 
access_log logs/host.access.log main; 日志配置 
location URI 匹配规则 
index index.html index.htm index.jsp; 默认页 
root /data/www/ha97; 主目录 
error_page 错误时返回给用户的页面

基本配置

server { 
    listen 8888; 
    location / { 
        root /datas/html/ordering/dist/; 
        index index.html index.htm; 
        }
    #用 ~开始匹配正则
    location ~.*.(gif|jpg|css|js|mp3|png){
        root /datas/html/web/;
        expires 3000d;
        } 
    #出现以下错误时返回 /50x.html页面 
    error_page 500 502 503 504 /50x.html; 
    location = /50x.html { 
        root html; 
        }
 }

反向代理,将访问8888的转到9999

server { 
    listen 8888; 
    location / { 
    proxy_pass http://127.0.0.1:9999; 
    } 
}

负载均衡的反向代理,自定义一个myupstream

server { 
    listen 8888; 
    location / { 
        proxy_pass http://myupstream; 
        } 
    } 
    #weight 权重 指定轮询几率,weight和访问比率成正比,用于后端服务器性能不均的情况。 
upstream myupstream{ 
    # 表示当前的server暂时不参与负载
    server 127.0.0.1:8050 weight=10 down; 
    server 127.0.0.1:8060 weight=1; 
    #其它所有的非backup机器down或者忙的时候,请求backup机器。
    server 127.0.0.1:8070 weight=1 backup; 
}

ssl配置https请求

server { 
    #SSL 访问端口号为 443(可以是任意端口) 
    listen 443 ssl; 
    #填写绑定证书的域名 
    server_name duozuiyu.com; 
    #证书文件名称 
    ssl_certificate duozuiyu.com.crt; 
    #私钥文件名称 
    ssl_certificate_key duozuiyu.com.key; 
    location / { 
        #网站主页路径。此路径仅供参考,具体请您按照实际目录操作。 
        root html; 
        index index.html index.htm; 
        } 
    }

可能编译时报错

nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:98

nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed

解决方法:

  1. 重新编译 增加ssl模块

./configure --with-http_stub_status_module --with-http_ssl_module

  1. 执行 make

make执行完之后 不要执行install

  1. 备份
  2. 替换文件
  3. 启动Nginx
  4. 访问https

免费签名

FreeSSL首页 - FreeSSL.cn一个提供免费HTTPS证书申请的网站

阿里云

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/676242.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号