服务端部署
本地可以使用proxyTable 解决跨域问题,那么服务端怎么解决跨域问题呢?
answer:使用nginx反向代理
nginx配置: 仔细分析一下看看是否适合自己的业务场景
server
{
listen 80;
#listen [::]:80;
server_name zhenfan.shudong.wang ; # 你的域名不需要加http
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/zhenfan/dist; include none.conf;
#error_page 404 /404.html;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*.php$ { deny all; }
include enable-php.conf;
location /v1 {
proxy_pass http://127.0.0.1:3000/; # 当访问v1的时候默认转发到 3000端口
}
location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /.
{
deny all;
}
access_log off;
}
关于express链接mongodb可以直接填写端口号,不存在跨域问题,直接 127.0.0.1:27017就ok,
怎么在服务器上面搭建可以参考上篇 mongodb篇
关于有什么问题,可以在下面留言,希望你是来讨论技术的。
上次写完一篇,一个小朋友,来到这里咬文嚼字,针对 部署这个词,说用的不当,还口口声声说是来讨论技术,把注意力放在这个上面上真没意义。
希望本篇文章能帮到你,解决你的问题。 也希望大家多多支持软件开发网。










