# 一.项目中配置

# 1.dev配置

server {
     server_name dev.zhoubichuan.com;

     location ~*^.+$ {
          gzip on;
          gzip_min_length 1k;
          gzip_http_version 1.1;
          gzip_comp_level 9;
          gzip_types text/css application/javascript;
          root /usr/src/zhoubichuan/dev/;
          try_files $uri $uri/ /index.html;
          index index.html index.htm;
     }

     location ^~/common-node/api {
          proxy_pass http://localhost:3000/api;
     }

     location ^~/antdpro-express/api {
          proxy_pass http://localhost:7001/api;
     }

     location ^~/abstract-express/api {
          proxy_pass http://localhost:7005/api;
     }

     location ^~/abstract-egg/api {
          proxy_pass http://localhost:7006/api;
     }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

# 2.sit配置

server {
     server_name sit.zhoubichuan.com;

     location ~*^.+$ {
          gzip on;
          gzip_min_length 1k;
          gzip_http_version 1.1;
          gzip_comp_level 9;
          gzip_types text/css application/javascript;
          root /usr/src/zhoubichuan/sit/;
          try_files $uri $uri/ /index.html;
          index index.html index.htm;
     }

     location ^~/common-node/api {
          proxy_pass http://localhost:3000/api;
     }

     location ^~/antdpro-express/api {
          proxy_pass http://localhost:7001/api;
     }

     location ^~/abstract-express/api {
          proxy_pass http://localhost:7005/api;
     }

     location ^~/abstract-egg/api {
          proxy_pass http://localhost:7006/api;
     }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

# 3.uat配置

server {
     server_name uat.zhoubichuan.com;

     location ~*^.+$ {
          gzip on;
          gzip_min_length 1k;
          gzip_http_version 1.1;
          gzip_comp_level 9;
          gzip_types text/css application/javascript;
          root /usr/src/zhoubichuan/uat/;
          try_files $uri $uri/ /index.html;
          index index.html index.htm;
     }

     location ^~/common-node/api {
          proxy_pass http://localhost:3000/api;
     }

     location ^~/antdpro-express/api {
          proxy_pass http://localhost:7001/api;
     }

     location ^~/abstract-express/api {
          proxy_pass http://localhost:7005/api;
     }

     location ^~/abstract-egg/api {
          proxy_pass http://localhost:7006/api;
     }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

# 4.pet配置

server {
     server_name pet.zhoubichuan.com;

     location ~*^.+$ {
          gzip on;
          gzip_min_length 1k;
          gzip_http_version 1.1;
          gzip_comp_level 9;
          gzip_types text/css application/javascript;
          root /usr/src/zhoubichuan/pet/;
          try_files $uri $uri/ /index.html;
          index index.html index.htm;
     }

     location ^~/common-node/api {
          proxy_pass http://localhost:3000/api;
     }

     location ^~/antdpro-express/api {
          proxy_pass http://localhost:7001/api;
     }

     location ^~/abstract-express/api {
          proxy_pass http://localhost:7005/api;
     }

     location ^~/abstract-egg/api {
          proxy_pass http://localhost:7006/api;
     }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

# 5.sim配置

server {
     server_name sim.zhoubichuan.com;

     location ~*^.+$ {
          gzip on;
          gzip_min_length 1k;
          gzip_http_version 1.1;
          gzip_comp_level 9;
          gzip_types text/css application/javascript;
          root /usr/src/zhoubichuan/sim/;
          try_files $uri $uri/ /index.html;
          index index.html index.htm;
     }

     location ^~/common-node/api {
          proxy_pass http://localhost:3000/api;
     }

     location ^~/antdpro-express/api {
          proxy_pass http://localhost:7001/api;
     }

     location ^~/abstract-express/api {
          proxy_pass http://localhost:7005/api;
     }

     location ^~/abstract-egg/api {
          proxy_pass http://localhost:7006/api;
     }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

# 6.prod配置

server {
     server_name zhoubichuan.com; # 填写相应的子域名,不需要加 https:// 的前缀。填写这个使得 Nginx 可以正确匹配不同子域的请求

     location ~*^.+$ {
          gzip on;
          gzip_min_length 1k;
          gzip_http_version 1.1;
          gzip_comp_level 9;
          gzip_types text/css application/javascript;
          root /usr/src/zhoubichuan/prod/; # 指示这个子域名所对应的文件夹根目录的位置
          try_files $uri $uri/ /index.html;
          index index.html index.htm; # 显示主页时所使用的文件名
     }

     location ^~/common-node/api {
          proxy_pass http://localhost:3000/api;
     }

     location ^~/antdpro-express/api {
          proxy_pass http://localhost:7001/api;
     }

     location ^~/abstract-express/api {
          proxy_pass http://localhost:7005/api;
     }

     location ^~/abstract-egg/api {
          proxy_pass http://localhost:7006/api;
     }

     location /child/resume {
     root   html;
     index  index.html index.htm;
     try_files $uri $uri/ /child/resume/index.html;
     }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

# 7.micro配置

server {
     server_name micro.zhoubichuan.com;

     location ~*^.+$ {
          gzip on;
          gzip_min_length 1k;
          gzip_http_version 1.1;
          gzip_comp_level 9;
          gzip_types text/css application/javascript;
          root /usr/src/zhoubichuan/micro/;
          try_files $uri $uri/ /index.html;
          index index.html index.htm;
     }

     location ^~/common-node/api {
          proxy_pass http://localhost:3000/api;
     }

     location ^~/antdpro-express/api {
          proxy_pass http://localhost:7001/api;
          # include /etc/nginx/conf.d/*.conf;
     }

     location ^~/abstract-express/api {
          proxy_pass http://localhost:7005/api;
     }

     location ^~/abstract-egg/api {
          proxy_pass http://localhost:7006/api;
     }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

# 9.http配置

server {
     listen 80; # Nginx 要监听 80 号端口
     server_name _; # 无论什么 hostname 都会被匹配
     return 301 https://$host$request_uri; # 用户的 HTTP 请求永久重定向(301 Moved Permanently)到 HTTPS 那边,并且保证链接的剩余部分不变
}
1
2
3
4
5

# 10.https配置



server {
     listen 443 ssl; # managed by Certbot
     ssl_certificate /etc/letsencrypt/live/zhoubichuan.com/fullchain.pem; # managed by Certbot
     ssl_certificate_key /etc/letsencrypt/live/zhoubichuan.com/privkey.pem; # managed by Certbot
     include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
     ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

     error_page 500 502 503 504 /50x.html;
     location = /50x.html {
          root /usr/share/nginx/html;
     }
}
1
2
3
4
5
6
7
8
9
10
11
12
13

# 9.默认配置

server {
    server_name zhoubichuan.com;

     location ~*^.+$ {
          gzip on;
          gzip_min_length 1k;
          gzip_http_version 1.1;
          gzip_comp_level 9;
          gzip_types  text/css application/javascript;
          root   /usr/src/zhoubichuan/prod/;
          try_files $uri $uri/ /index.html;
          index  index.html index.htm;
      }

     location  ^~/common-node/api {
          proxy_pass http://localhost:3000/api;
      }

     location ^~/antdpro-express/api {
          proxy_pass http://localhost:7001/api;
          # include /etc/nginx/conf.d/*.conf;
     }

     location ^~/abstract-express/api {
          proxy_pass http://localhost:7005/api;
     }

     location ^~/abstract-egg/api {
          proxy_pass http://localhost:7006/api;
     }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;

    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}
                                                                                                                                                                                          1,8          顶端

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/zhoubichuan.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/zhoubichuan.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server {
    if ($host = zhoubichuan.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen       80;
    server_name zhoubichuan.com;
    return 404; # managed by Certbot

}
                                                                                                                                                                                          89,1         底端
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
刷新
全屏/自适应