Sun's blog Sun's blog
首页
  • HTML
  • CSS
  • JavaScript基础
  • JavaScript高级
  • Git
  • Webpack
  • Vite
  • Vue
  • React
  • Node

    • Node基础
    • Nest
  • Flutter基础

    • 00.Dart环境搭建
    • 01.Dart入口注释变量常量命名规则
    • 02.Dart的数据类型详解int double String bool List Maps
    • 03.Dart运算符 条件表达式 Dart类型转换
    • 04.Dart循环语句 for while do while break continue多维列表循环
    • 05.Dart 集合类型List Set Map详解 以及循环语句 forEach map where any every
  • Go基础

    • Go语言基础
  • mongodb

    • mongodb
    • mongoose
  • mysql

    • mysql
    • sequelize
  • redis

    • redis
  • Linux
  • Nginx
  • 学习方法

    • 费曼学习法
    • 笔记方法
    • 提高学习效率的策略
    • 提高记忆的技巧
  • 前端常用

    • 常用网站
    • 常用的前端轮子
    • 面试问题
    • Markdown
  • 友情链接

    • 友情链接
  • 日语
  • 英语

    • 国际音标
    • 新概念第一册
  • 小滴课堂

    • 后端项目
    • 前端项目
    • 后台管理
    • Nuxt的基础使用
    • Linux安装环境
    • Node基础
GitHub (opens new window)

Sun Tang

何以解忧,唯有不断学习变强,强大才可以无惧一切!
首页
  • HTML
  • CSS
  • JavaScript基础
  • JavaScript高级
  • Git
  • Webpack
  • Vite
  • Vue
  • React
  • Node

    • Node基础
    • Nest
  • Flutter基础

    • 00.Dart环境搭建
    • 01.Dart入口注释变量常量命名规则
    • 02.Dart的数据类型详解int double String bool List Maps
    • 03.Dart运算符 条件表达式 Dart类型转换
    • 04.Dart循环语句 for while do while break continue多维列表循环
    • 05.Dart 集合类型List Set Map详解 以及循环语句 forEach map where any every
  • Go基础

    • Go语言基础
  • mongodb

    • mongodb
    • mongoose
  • mysql

    • mysql
    • sequelize
  • redis

    • redis
  • Linux
  • Nginx
  • 学习方法

    • 费曼学习法
    • 笔记方法
    • 提高学习效率的策略
    • 提高记忆的技巧
  • 前端常用

    • 常用网站
    • 常用的前端轮子
    • 面试问题
    • Markdown
  • 友情链接

    • 友情链接
  • 日语
  • 英语

    • 国际音标
    • 新概念第一册
  • 小滴课堂

    • 后端项目
    • 前端项目
    • 后台管理
    • Nuxt的基础使用
    • Linux安装环境
    • Node基础
GitHub (opens new window)
  • Linux

  • Nginx

    • Nginx 基础配置
      • Nginx 配置
        • ip 地址部署三端
        • 域名部署三端项目
  • 运维
  • Nginx
Sun
2023-09-01

Nginx 基础配置

# Nginx 配置

# ip 地址部署三端

# 存放目录

服务器目录: etc -> nginx -> conf.d

# default.conf

server {
    listen       80;
    server_name  localhost;

    #access_log  /var/log/nginx/host.access.log  main;

#     location / {
#         root   /usr/share/nginx/html;
#         index  index.html index.htm;
#     }
    location / {
        #root   /usr/share/nginx/html;
	    root /home/h5/dist;
        index  index.html index.htm;
    }
    location @router {
    	rewrite ^.*$ /index.html last; # 关键一句
    }
    location /cms{
    	alias /home/admin/dist;
    	index index.html index.htm;
    	try_files $uri $uri/ @router;
    }
    # 图片静态目录
    location /uploads {
        root /home/server/public;
        add_header Cache-Control no-cache;
        add_header Access-Control-Allow-Origin *;
    }
    # m3u8 静态目录
    location /uploads/video {
	    types {
	        application/vnd.apple.mpegurl m3u8;
	        video/mp2t ts;
	    }
    	root /home/server/public;
	    add_header Cache-Control no-cache;
	    add_header Access-Control-Allow-Origin *;
    }

    # location / {
    #   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_set_header Via "nginx";
	# 	proxy_pass http://localhost:9000;
    # }


    # 后端代码代理
    location ^~ /api/v1 {
        proxy_pass http://localhost:9000;
        proxy_redirect off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        client_max_body_size 5000m;                           # 允许客户端请求的最大单文件字节数
        client_body_buffer_size 128k;                         # 缓冲区代理缓冲用户端请求的最大字节数,
        proxy_connect_timeout 90;                             # nginx跟后端服务器连接超时时间(代理连接超时)
        proxy_send_timeout 90;                                # 后端服务器数据回传时间(代理发送超时)
        proxy_read_timeout 90;                                # 连接成功后,后端服务器响应时间(代理接收超时)
        proxy_buffer_size 4k;                                 # 设置代理服务器(nginx)保存用户头信息的缓冲区大小
        proxy_buffers 4 32k;                                  # proxy_buffers缓冲区,网页平均在32k以下的设置
        proxy_busy_buffers_size 64k;                          # 高负荷下缓冲大小(proxy_buffers*2)
        proxy_temp_file_write_size 64k;
    }
    #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;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99

# 域名部署三端项目

# 存放目录

服务器目录: etc -> ngnix -> conf.d

# default.conf

server {
    listen 80 default_server;
    server_name _;

    location / {
        return 404;
    }
}

1
2
3
4
5
6
7
8
9

# api.conf

server {
    listen      80;
    server_name api.xxx.com;
        access_log  /var/log/nginx/api_access.log  main;

    # m3u8 静态目录
    location /uploads/video {
	    types {
	        application/vnd.apple.mpegurl m3u8;
	        video/mp2t ts;
	    }
    	root /home/server/public;
        add_header Cache-Control no-cache;
	    add_header Access-Control-Allow-Origin *;
    }

    # 图片静态目录
    location /uploads {
        root /home/server/public;
        add_header Cache-Control no-cache;
        add_header Access-Control-Allow-Origin *;
    }

    # location / {
    #   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_set_header Via "nginx";
	# 	proxy_pass http://localhost:9000;
    # }
    location ^~ /api/v1 {
        proxy_pass http://localhost:9000;
        proxy_redirect off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        client_max_body_size 5000m;                           # 允许客户端请求的最大单文件字节数
        client_body_buffer_size 128k;                         # 缓冲区代理缓冲用户端请求的最大字节数,
        proxy_connect_timeout 90;                             # nginx跟后端服务器连接超时时间(代理连接超时)
        proxy_send_timeout 90;                                # 后端服务器数据回传时间(代理发送超时)
        proxy_read_timeout 90;                                # 连接成功后,后端服务器响应时间(代理接收超时)
        proxy_buffer_size 4k;                                 # 设置代理服务器(nginx)保存用户头信息的缓冲区大小
        proxy_buffers 4 32k;                                  # proxy_buffers缓冲区,网页平均在32k以下的设置
        proxy_busy_buffers_size 64k;                          # 高负荷下缓冲大小(proxy_buffers*2)
        proxy_temp_file_write_size 64k;
    }
}

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

# admin.conf

server {
    listen       80;
    server_name  admin.xxx.com;
    access_log  /var/log/nginx/admin_access.log  main;


    location @router {
       rewrite ^.*$ /index.html last; # 关键一句
    }

    # m3u8 静态目录
    location /uploads/video {
	    types {
	        application/vnd.apple.mpegurl m3u8;
	        video/mp2t ts;
	    }
    	root /home/server/public;
        add_header Cache-Control no-cache;
	    add_header Access-Control-Allow-Origin *;
    }

    # 图片静态目录
    location /uploads {
        root /home/server/public;
        add_header Cache-Control no-cache;
        add_header Access-Control-Allow-Origin *;
    }

    location / {
        root /home/admin/dist/;
        index index.html index.htm;
        #try_files $uri $uri/ @router;
    }
    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
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

# h5.conf

server {
    listen       80;
    server_name  xxx.com www.xxx.com m.xxx.com;
    access_log  /var/log/nginx/h5_access.log  main;

    location @router {
        rewrite ^.*$ /index.html last; # 关键一句
    }

    # m3u8 静态目录
    location /uploads/video {
	    types {
	        application/vnd.apple.mpegurl m3u8;
	        video/mp2t ts;
	    }
    	root /home/server/public;
        add_header Cache-Control no-cache;
	    add_header Access-Control-Allow-Origin *;
    }

    # 图片静态目录
    location /uploads {
        root /home/server/public;
        add_header Cache-Control no-cache;
        add_header Access-Control-Allow-Origin *;
    }

    location / {
        #root   /usr/share/nginx/html;
        root /home/h5/dist;
        index  index.html index.htm;
    }
}

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
编辑 (opens new window)
上次更新: 2024/04/20, 18:53:06
Linux

← Linux

最近更新
01
Node基础
07-23
02
05.Dart 集合类型List Set Map详解 以及循环语句 forEach map where any every
05-08
03
04.Dart循环语句 for while do while break continue多维列表循环
05-08
更多文章>
Theme by Vdoing | Copyright © 2019-2024 Sun Tang | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式