Front and rear ends react complete separation of pure front-end deployment problems, server denied access

I. Introduction

Recently wrote a project that will separate the front page and api, deployment time due to the development of front-end server or used only for this machine open the port, there have been some problems in the external network access on the server is less than

In fact, you can install a global http-server module

$npm install -g http-server
$cd dist
$hs

Here Insert Picture Description
This is can be accessed via ip to the whole network for

If you are using nginx or apache server is pointing to this page also can be compiled, but I'm too lazy to get there is a problem
the following step on the pit to record what process (in fact, the brain pumping, and deployment time, how can I use the dev-server it)

Second, there is a problem

On the server running npm run start, then some tips to normal,
but when accessed via ip or domain name is not access to.
Appears Access is denied.

Third, try to resolve failed

Since I bought the server, I thought it was my configuration, I would configure the firewall security group and
I are centos7
centos7 firewall is a firewall (centos6 is iptables)

添加开放端口
firewall-cmd --zone=public --add-port=8082/tcp --permanent   (--permanent永久生效,没有此参数重启后失效)
重新载入
firewall-cmd --reload
查看
firewall-cmd --zone=public --query-port=8082/tcp

Safety set of rules
Here Insert Picture Description
but still does not work,

Fourth, find the answer

I was going to ask the customer service work order issued. . . See the following description on Ali says:
[
investigation port 80 is unavailable
execute the following command to check the TCP 80 port is being monitored.
netstat -an | grep 80
The system displays similar to the following, if any of the following result is returned, indicating that it has started TCP 80 port of Web services.

tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN 
# 全网监听
tcp        0      0 127.0.0.1:80            0.0.0.0:*               LISTEN 
# 本机监听

注:本机127.0.0.1监听会导致外网无法访问Web服务,只有本机能访问,需修改为全网监听。
]
Looked at me
Here Insert Picture Description
really wrong, so I went webpack configuration file (config / index.js) was changed host

  var path = require('path')
   
  module.exports = {
    build: {
      index: path.resolve(__dirname, 'dist/index.html'),
      assetsRoot: path.resolve(__dirname, 'dist'),
      assetsSubDirectory: 'static',
      assetsPublicPath: '/',
      productionSourceMap: true
   },
   dev: {
     port: 8080,
     host:'0.0.0.0' //默认为127.0.0.1在外网无法访问改为0.0.0.0对全网可访问
     proxyTable: {}
   }
 }

nodejs the http module will not happen this issue.
So is the whole network monitor.
Then you can visit, and we still try not to put a real development server on a server running

Published 14 original articles · won praise 8 · views 6134

Guess you like

Origin blog.csdn.net/KangTongShun/article/details/104459773