我这有一个网上下载好的一个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
闪动一下代表启动成功
完事我们在去访问
在这里插入图片描述
配置完毕