Nginx跨域

300 阅读1分钟

下载ngnix后,打开安装目录输入cmd

显示出版本号就证明安装成功,打开conf文件夹,找到nginx.conf文件,修改配置,/apis设置为反向代理

server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   C:/Users/kiloworld/Desktop/text/orgchart; //文件根目录
            index  index.html index.htm; //默认起始页
        }
        
       location /apis {
			rewrite  ^.+apis/?(.*)$ /$1 break;
			include  uwsgi_params;
			proxy_pass   http://test.qianqianshijie.com;
       }

        #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;
        #}

具体应该是 php-fpm 处理php脚本的端口吧, 改成 proxy_pass http://127.0.0.1:9000 就可以访问了