|
在nginx中需要配置多个项目,所以需要配置多个server,配置如下:
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 81;
server_name test;
location / {
root html/test;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
location /api/ {
proxy_pass http://172.16.8.9:8888/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 82;
server_name test2;
location / {
root html/test2;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
location /api/ {
proxy_pass http://172.16.8.9:8888/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
location /api/ {
proxy_pass http://172.16.8.9:8888/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}步骤1:html 下创建多个文件夹,不同的项目放到不同的文件夹下如上:server_name为test2 的,访问路径就是 html/test2 步骤2:为不同的文件夹,配置不同的server, 端口号不同 步骤3:host文件去为server作映射 host文件地址:C:\Windows\System32\drivers\etc 打开host文件, 添加如下代码: 127.0.0.1 test 127.0.0.1 test2 步骤4:访问 使用 test:81 , 即可访问到 html/test 文件夹下面的项目 使用 test2:82 ,即可以访问 html/test2 文件夹下面的项目 |
|
|