在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/Linux  HTML/ 請(qǐng)教一個(gè)nginx配置反向代理的問(wèn)題

請(qǐng)教一個(gè)nginx配置反向代理的問(wèn)題

本地跨域配置實(shí)用的是proxy,本地測(cè)試跨域沒(méi)有問(wèn)題,數(shù)據(jù)能正常接受,后臺(tái)能console

  "/api": {
    "target": "http://132.232.22.140:8889/api",
    "changeOrigin": true,
    "pathRewrite": { "^/api" : "" }
  }

部署到服務(wù)器后,nginx配置

server {
        listen 8000;
        # server_name www.alatu..xyz;

        root /home/myftp/dist;
        index index.html index.htm;

        location / {
                try_files $uri $uri/ /index.html;
        }
        location ^~ /assets/ {
                gzip_static on;
                expires max;
                add_header Cache-Control public;
        }
location /api {
    rewrite  ^.+api/?(.*)$ /$1 break;
    include  uwsgi_params;
       proxy_pass   http://localhost:8889;
       }
        error_page 500 502 503 504 /500.html;
        client_max_body_size 20M;
        keepalive_timeout 10;
}

線上測(cè)試收不到數(shù)據(jù),后臺(tái)也沒(méi)有console啊,有沒(méi)有前輩幫忙看看,不甚感激!

回答
編輯回答
刮刮樂(lè)

看nginx日志,包括access_log和error_log

2017年3月22日 11:13
編輯回答
殘淚

結(jié)案了,原來(lái)最大的問(wèn)題是我的后臺(tái)沒(méi)寫(xiě)對(duì),url寫(xiě)錯(cuò)了

    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  132.232.22.140:8000;
        root         /usr/share/nginx/html;
#       root          /home/myftp/dist

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location ^~ /api/ {
            proxy_pass http://127.0.0.1:8889;
        }
        location /{
                proxy_pass   http://127.0.0.1:8000;
        }
        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
    

8000前端端口,8889后臺(tái)端口,這樣寫(xiě)就跨域成功了

2018年9月21日 01:05