nginx.conf
Full Example Configuration (opens new window)
目录结构
/
├── opt
│ ├── install
│ ├── package
│ └── source
│ └── backend
│ │ └── hold-on
│ └── frontend
│ ├── GitBook
│ │ └── OnJava8
│ ├── vue
│ │ └── admin
│ └── vuepress
│ ├── docs
│ └── fobgochod
├── root(me)
└── usr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
创建目录
mkdir -p /opt/{install,package,source/{backend/hold-on,frontend/{GitBook/OnJava8,vue/admin,vuepress/{docs,fobgochod}}}}
1
修改nginx.conf添加一行
include /opt/install/nginx/conf.d/*.conf;
保证了/opt/install/nginx/conf.d/
下,所有以.conf结尾的配置文件, 都会被主配置文件nginx.conf引入并生效
mkdir -p /opt/install/nginx/conf.d
vi /opt/install/nginx/nginx.conf
http {
include mime.types;
default_type application/octet-stream;
include /opt/install/nginx/conf.d/*.conf;
}
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
静态站点(vuepress、gitbook)
注:
- 网站部署到
http://zhouxiao.co/docs/
,那么config.js
的base
应该被设置成"/docs/"
server {
listen 80;
server_name localhost;
access_log logs/access.localhost.log main;
location / {
root html;
index index.html index.htm;
}
# 1
location /docs {
alias /opt/source/frontend/vuepress/fobgochod/dist;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location /onjava8 {
alias /opt/source/frontend/GitBook/OnJava8/_book;
index index.html index.htm;
try_files $uri $uri/ /index.html;;
}
location /docs/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://localhost:7001/;
}
}
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
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
vue
server {
listen 80;
server_name localhost;
access_log logs/access.localhost.log;
location /admin {
alias /opt/source/frontend/vue/admin/dist;
try_files $uri $uri/ @router;
index index.html index.htm;
}
location @router {
rewrite ^.*$ /admin/index.html last;
}
location /admin/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://localhost:7002/;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
后端服务
注:
- 访问
http://zhouxiao.co/api/v1/
,会实际访问http://localhost:7003/api/v1
- 访问
http://zhouxiao.co/console/api/v1/
,会实际访问http://localhost:7004/api/v1
server {
listen 80;
server_name localhost;
access_log logs/access.localhost.log;
# 1
location /api/v1 {
proxy_pass http://localhost:7003;
}
# 2 多了一个/
location /console/ {
proxy_pass http://localhost:7004/;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
二级域名
server {
listen 80;
server_name docs.zhouxiao.co;
access_log logs/access.docs.zhouxiao.co.log;
root /opt/source/frontend/vuepress/docs/dist;
location / {
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13