具体操作详解:
进入到nginx安装目录的配置文件中下:vim /usr/local/nginx/conf/nginx.conf
编辑
server {
listen 80;
server_name dzf1.com;
index index.html index.htm index.php;
root /data/html/dist; // 代表html路径 (存储在服务器的文件目录)
if ($host != 'dzf1.com'){
return 403;
}
location / {
try_files $uri $uri/ /index.html;
index index.html;
}
location ^~ /api { // 这个地方配置得是代理
proxy_pass http://127.0.0.1:4999 // 配置代理的地址;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
}
}
上述配置的意思:只要监听到对这个地址的访问 http://localhost:80地址,就会跳转到 http://127.0.0.1:4999,接口申请的数据也是通过这个接口;