nginx部署react项目

1.build项目

build注意要配置webpack的webpack.config.prod.js文件,生产环境的配置(我是使用的less,所以加了个less的loader)

yarn build

2.配置nginx

由于使用的是browserRouter,所以要用nginx把所有路由指向index.html
所以配置以下(我页面放html/build里的)

        location / {
            root   html/build;
            index  index.html index.htm;
            try_files $uri $uri/ /index.html =404;
        }

由于后台接口跨域,所以要用nginx配置跨域

        location /api/console {
            proxy_pass http://127.0.0.1:8080/console;
        }

        location /api {
            proxy_pass http://127.0.0.1:8080;
        }

3.参考

http://www.cnblogs.com/souvenir/p/5647504.html
http://blog.csdn.net/zhangliangzi/article/details/52143358
http://blog.csdn.net/boonya/article/details/73776789

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。