与SSH连接时如何运行本地主机地址

时间:2020-09-25 21:51:36

标签: amazon-web-services npm ssh deployment

首先-对最可能出现的愚蠢问题表示歉意,我是该领域的初学者。我已通过ssh连接到AWS服务器,并且已成功安装Elasticsearch并传输了要与npm一起运行的应用程序。在我的本地计算机上,当我运行npm start时,我被转移到http://localhost:3000/,一切正常。我如何查看该应用程序是否也在AWS服务器上正常工作?有没有办法打开浏览器或类似的东西?到目前为止,我仅与终端进行交互。

谢谢!

编辑:命令curl http://localhost:3000/输出以下内容:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <link rel="icon" href="/favicon.ico" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="theme-color" content="#000000" />
    <meta
      name="description"
      content="Web site created using create-react-app"
    />
    <link rel="apple-touch-icon" href="/logo192.png" />
    <!--
      manifest.json provides metadata used when your web app is installed on a
      user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
    -->
    <link rel="manifest" href="/manifest.json" />
    <!--
      Notice the use of  in the tags above.
      It will be replaced with the URL of the `public` folder during the build.
      Only files inside the `public` folder can be referenced from the HTML.

      Unlike "/favicon.ico" or "favicon.ico", "/favicon.ico" will
      work correctly both with client-side routing and a non-root public URL.
      Learn how to configure a non-root public URL by running `npm run build`.
    -->
    <title>React App</title>
  </head>
  <body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root"></div>
    <!--
      This HTML file is a template.
      If you open it directly in the browser, you will see an empty page.

      You can add webfonts, meta tags, or analytics to this file.
      The build step will place the bundled scripts into the <body> tag.

      To begin the development, run `npm start` or `yarn start`.
      To create a production bundle, use `npm run build` or `yarn build`.
    -->
  <script src="/static/js/bundle.js"></script><script src="/static/js/0.chunk.js"></script><script src="/static/js/main.chunk.js"></script></body>
</html>

2 个答案:

答案 0 :(得分:0)

尝试curl http://localhost:3000/确认可以连接。这是一个很好的快速测试,可以确认您是否有正常的服务。

答案 1 :(得分:0)

npm buildlocalhost上启动开发服务器并加载页面。 package.json文件的脚本部分将指示您是否有构建脚本(您可能有)。

在package.json文件中,应该有一个类似于以下内容的对象:

"scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "test:cov": "npm test -- --coverage --watchAll=false",
    "test:debug": "react-scripts --inspect-brk test --runInBand",
    "eject": "react-scripts eject"
}

(您的开始行和构建行可能看起来不同,但这很好)

您的构建脚本将创建生产构建,并且可能会在构建脚本完成后将其放置在/ build或/ public目录中。

因此,请在本地计算机上的命令行中尝试npm build而不是npm start。然后,您可以将/ build(或/ public)目录的内容放到AWS服务器上(作为具有80和443端口的网络服务器运行,以供公众访问),然后可以通过IP地址或域访问该站点。名称,如果您已通过Route53将A记录映射到服务器的IP。