鍍金池/ 問答/Linux  HTML/ nginx反向代理跨域失敗

nginx反向代理跨域失敗

前端端口 nginx配置

server {
        listen 8000;
       # server_name _;

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

        location  /apis {
            rewrite  ^.+apis/?(.*)$ /$1 break;
            include  uwsgi_params;
              proxy_pass   http://127.0.0.1:8889;
       }
        location / {
                try_files $uri $uri/ /index.html;
        }
        error_page 500 502 503 504 /500.html;
        client_max_body_size 20M;
        keepalive_timeout 10;
}

nginx.conf

events {
    worker_connections 1024;
}

http {
    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  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
   # include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/vhost/*.conf;

    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 /{
                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 {
        }
    }

下載了ssl證書,域名還在備案
后端服務接受不到數(shù)據(jù)

控制臺查看的話是
圖片描述

是哪里錯了呀,都是在網(wǎng)上看的教程。。。求大大看看

回答
編輯回答
執(zhí)念

結案了,原因是因為我在本地proxy配置用的是api/xxxx,導致我認為后臺代碼沒有一點問題,結果這里是apis

    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端口,跨域成功

2017年11月20日 23:53
編輯回答
久舊酒
listen       80 default_server;
listen       [::]:80 default_server;
server_name  132.232.22.140:8000;

改成

listen       8000;
server_name  132.232.22.140;
2017年9月5日 20:49