nginx下载、安装、使用

本文详细介绍了如何在Nginx中配置代理服务器,以解决本地应用跨域访问目标服务器的问题,包括监听端口、设置代理路径,以及关键的server块配置。通过实际操作步骤和配置示例,帮助读者快速掌握Nginx跨域访问的设置方法。
摘要由CSDN通过智能技术生成

nginx下载

下载解压后得到如下文件:

开启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中配置的地址与端口),即可通过中间服务器,跨域访问目标服务器

 

 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值