账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    如何在nginx上的同一域名及端口上配置两个打包后的react应用?
    55
    0
    server {
        listen       80;
        server_name  localhost;
    
        location /a {
            root   /test/nginx/a;
            index  index.html index.htm;
        try_files $uri /index.html =404;
        }
    
        location /b {
            root   /test/nginx/b;
            index  index.html index.htm;
        try_files $uri /index.html =404;
        }
    }
    

    目前的思路我这样写是没有用的!
    请问还有什么写法吗?

    1
    打赏
    收藏
    点击回答
        全部回答
    • 共 0 条
    • 花生哥哥 普通会员 1楼

      要在Nginx上配置两个打包后的React应用,您需要遵循以下步骤:

      1. 首先,安装必要的依赖项。对于React和Nginx,您需要安装以下依赖项: npm install --save express @babel/core @babel/preset-env webpack webpack-cli

      2. 创建一个名为server.js的文件,并添加以下代码以配置Nginx和React应用: ```javascript const express = require('express'); const path = require('path'); const webpack = require('webpack'); const webpack-cli = require('webpack-cli');

      const app = express(); const webpackConfig = require('./webpack.config');

      app.use(webpackConfig.output);

      const devServer = new webpack和发展Server(webpackConfig);

      app.use((req, res, next) => { devServer.handle(req, res); next(); });

      module.exports = { devServer, }; ```

      1. 创建一个名为webpack.config.js的文件,并添加以下代码以配置Webpack: javascript module.exports = { entry: './src/index.js', output: { path: path.resolve(__dirname, 'dist'), filename: 'bundle.js', }, module: { rules: [ { test: /\.js$/, use: { loader: 'babel-loader', options: { presets: ['@babel/preset-env'], }, }, }, ], }, };

      2. 运行Nginx和React应用: npm start

      现在,您可以在同一域名及端口上访问两个打包后的React应用。您可以在浏览器中访问http://localhost:3000,然后在终端中运行npm run start以启动Nginx和React应用。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部