html 服务管理(Package.json)+ nginx

我这有一个网上下载好的一个html模板 但是我想让他用idea的插件启动服务那么就得让其进行如下配置
前提是已安装npm,nodejs等(如何配置npm,node.js网上自己搜索博主在这里就不进行说明了)

博主的文件形式(用的工具是idea)
在这里插入图片描述
找到该文件存放的根目录(全选输入命令cmd,即可进入cmd命令行)
![在这里插入图片描述](https://img-blog.csdnimg.cn/2020010800130161.png在这里插入图片描述在这里插入图片描述
在命令行输入 npm init 即可,
在这里插入图片描述
之后会出现一大堆提示直接一直回车即可(这里是设置一些属性)
在这里插入图片描述结束让你输入是否确认(不用管它直接回车即可,默认是yes)
在这里插入图片描述完成(会多一个文件Package.json)
在这里插入图片描述
然后我们 直接配置里面信息即可(这是原始的默认配制)

{
  "name": "congsuo_shoe_web",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

之后我们要配制端口号:

 {
  "name": "congsuo_shoe_web",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "server": "live-server --port=9000",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "congshuo",
  "license": "ISC"
}

在这里插入图片描述因为我在idea上装了相关vue的插件直接运行即可不用输入命令行
在这里插入图片描述如果没有下载 直接下即可
运行看效果:
在这里插入图片描述
127.0.0.1:9000就是我们设置的端口号(测试成功)但是这样做并不好,没有域名,那么我们现在就得用到我们之前讲到的nginx了

找到这个路径,配置本地host文件

C:\Windows\System32\drivers\etc

在这里插入图片描述
即可
看效果:
在这里插入图片描述但是我们的端口号还不能改变,怎么办,这时候就需要我们我之前讲过的nginx了

电脑安装nginx

打开nginx的核心配置文件 增加这么一段代码
include vhost/*.conf; # add config message
即可


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
	
	

	include vhost/*.conf; # add config message 
	
	
    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

然后我么建一个自己的文件夹vhost(这里如果有疑问可以看一下博主之前的nginx的文章)
F:\SoftWare\nginx-1.12.2\conf\vhost
在这个文件夹下建立一个 cs.conf(名字自己想随意)的文件

upstream cs-com{
	server	127.0.0.1:9000;
}

server {
	listen       80;
	server_name  www.cs.com;
	location / {  
	    proxy_pass   http://cs-com;
		
		proxy_connect_timeout 600;
		proxy_read_timeout 5000;
	}
}

在这里插入图片描述保存 选中 cmd打开即可
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
输入 start nginx.exe

在这里插入图片描述
闪动一下代表启动成功

完事我们在去访问
在这里插入图片描述
在这里插入图片描述配置完毕

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值