下载解压后得到如下文件:
开启nginx:双击最后一个应用程序,对话框一闪而过,则开启成功,可在任务管理器中看到
关闭操作:任务管理器中,右键结束进程
其中第一个conf配置文件中,在nginx.conf,配置本地地址接口,中间服务器,和目标服务器,最终实现跨域访问,地址在文件的server模块配置(前十行代码重点!!)
server {
listen 8080;
server_name localhost;
location / {
proxy_pass http://localhost:5500;
}
#虚拟的后端地址
location /jh-back/{
proxy_pass http://123.123.58.61:8031/jh-back/;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.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;
#}
}
配置完成后,
1、启动nginx,
2、在vscode中使用Live Server插件(在入口index.html使用),或右下角的Go Live启动程序,
3、Chrome里访问 localhost:8080/index.html (nginx中配置的地址与端口),即可通过中间服务器,跨域访问目标服务器