Nginx配置记录

nginx.conf

公共配置

#user  nobody;
worker_processes  1;


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

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
   server_names_hash_bucket_size 64;
	 client_max_body_size 100m;
    include       mime.types;
    default_type  application/octet-stream;
    #access_log  logs/access.log;
    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;
    
    # 网站维护时候注释下面这句话
    include ../vhost/*.conf;
    # 网站维护时候放开下面这句话
    #include ../vhost/upgrade/upgrade.conf;
    # 先定义日志格式,main是日志格式的名字
    log_format  main  
    	'$remote_addr - $remote_user [$time_local] "$request" 
        '$status $body_bytes_sent "$http_referer" '
        '"$http_user_agent" "$http_x_forwarded_for"';
    # 使用日志格式,也可以把这一行放到想记录访问日志的虚拟主机配置文件中去
    access_log  logs/access.log  main;                              
}

vhost文件夹

存放各个网站的配置

default.conf

禁止ip直接访问,跳转到index页面(下面自定义了,路径在html文件夹内)

server {
        listen 80 default; # 要禁止直接访问ip,需要加上default
        server_name ~.*;
        root   html;
        index  index.html;
} 
upgrade.conf

用做网站维护时使用,路径:vhost\upgrade\upgrade.conf

server {
    listen       80;
    server_name  localhost;
    #rewrite ^(.*)$ /upgrade/index.html break;
    location ~* ^.+\.(jpg|jpeg|gif|png|bmp|js|css|json)$ {
        access_log off;
        root html/upgrade;
        expires 30d;
        break;
    }
    location / {
        root   html/upgrade;
        rewrite ^(.*)$ /index.html break;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}
www.xxx.com.conf

示例网站配置

upstream web_us{  
    server 127.0.0.1:8080 max_fails=5 fail_timeout=30s;
}
server {
    listen 80;
    server_name www.xxx.com;
    location / {
       root   html;
       index  index.html index.htm;
       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;
       proxy_set_header    X-Forwarded-Proto  $scheme;
       proxy_pass http://web_us;
    }
    error_page 500 502 503 504  /50x.html;
    location = /50x.html {
            root   html;
    }
}
server {
    listen 443 ssl;
    server_name www.xxx.com;
    #设置ssl认证文件
    ssl_certificate ../ssl/nginx/www_xxx_com/4764632_www.xxx.com.pem;
    ssl_certificate_key ../ssl/nginx/www_xxx_com/4764632_www.xxx.com.key;
    ssl_session_cache    shared:SSL:1m;
    ssl_session_timeout  5m;

    ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers  on;
    #这里设置域名跳转名称不变
    server_name_in_redirect off;
    error_page 500 502 503 504  /50x.html;
    # 这里设置默认https跳转
    error_page 497 https://$host$uri?$args;

    location = /50x.html {
            root   html;
    }

    location / {
      proxy_redirect off;
      proxy_pass  http://web_us;
      proxy_set_header   X-Real-IP          $remote_addr;
      proxy_set_header   X-Forwarded-For    $proxy_add_x_forwarded_for;
      proxy_set_header   X-Forwarded-Proto  $scheme;
      proxy_set_header   X-Forwarded-Scheme $scheme;
      proxy_set_header   Host               $host;
      proxy_set_header   REMOTE-HOST        $remote_addr;
      proxy_set_header   X-NginX-Proxy      true;
      proxy_set_header   Connection "";
      proxy_http_version 1.1;
    }
}

index.html

修改默认的首页,可以设置当用ip访问时候显示的页面

在这里插入图片描述

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>没有找到站点</title>
<style>
*{margin:0;padding:0;color:#444}
body{font-size:14px;font-family:"宋体"}
.main{width:600px;margin:10% auto;}
.title{background: #20a53a;color: #fff;font-size: 16px;height: 40px;line-height: 40px;padding-left: 20px;}
.content{background-color:#f3f7f9; height:300px;border:1px dashed #c6d9b6;padding:20px}
.t1{border-bottom: 1px dashed #c6d9b6;color: #ff4000;font-weight: bold; margin: 0 0 20px; padding-bottom: 18px;}
.t2{margin-bottom:8px; font-weight:bold}
ol{margin:0 0 20px 22px;padding:0;}
ol li{line-height:30px}
</style>
</head>

<body>
    <div class="main">
        <div class="title">没有找到站点</div>
        <div class="content">
            <p class="t1">您的请求在Web服务器中没有找到对应的站点!</p>
            <p class="t2">可能原因:</p>
            <ol>
                <li>您没有将此域名或IP绑定到对应站点!</li>
                <li>配置文件未生效!</li>
            </ol>
            <p class="t2">如何解决:</p>
            <ol>
                <li>检查是否已经绑定到对应站点,若确认已绑定,请尝试重载Web服务;</li>
                <li>检查端口是否正确;</li>
                <li>若您使用了CDN产品,请尝试清除CDN缓存;</li>
                <li>普通网站访客,请联系网站管理员;</li>
            </ol>
        </div>
    </div>
</body>
</html>

网站升级配置

所需资源下载地址:https://download.csdn.net/download/u014440968/60207575
资源
在complete-time.json中配置维护结束时间
在这里插入图片描述

效果图

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Mr.李大哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值