【问题标题】:Nginx proxy pass 404 error - CORSNginx 代理传递 404 错误 - CORS
【发布时间】:2016-12-19 12:08:03
【问题描述】:

我已经为 JAVA Web 服务配置了 proxy_pass 以启用跨源。我可以使用 Web 服务 URL http://10.1.200.156:8080/ClientService/passwordReset/ 发送发布请求,但 http://10.1.200.156/ClientService/passwordReset/ 会给出 404 错误。客户端应用程序提供Response for preflight is invalid (redirect)。 在网上搜索后,我在 Nginx 配置中添加了proxy_set_header Host $http_host;,但仍然没有运气。下面,Nginx 配置。请帮忙。

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;

    include /etc/nginx/conf.d/*.conf;

    server {
    listen 80;
    server_name euca-172-16-10-214.eucalyptus.internal;

    location /ClientService/passwordReset/ {
        proxy_pass http://10.1.200.156:8080/ClientService/passwordReset/;

            if ($request_method = 'OPTIONS') {
                add_header 'Access-Control-Allow-Origin' '*';
                add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
                add_header 'Access-Control-Max-Age' 1728000;
                add_header 'Content-Type' 'text/plain charset=UTF-8';
                #add_header 'Content-Length' 0;
                return 204;
                }

            if ($request_method = 'POST') {
                add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Credentials' 'true';
                add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
                }

            if ($request_method = 'GET') {
                add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Credentials' 'true';
                add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
                }
        }
    }
}

【问题讨论】:

  • 代理时不应包含 URI。 proxy_pass http://10.1.200.156:8080;
  • 谢谢它现在正在工作。
  • 很高兴能帮上忙。请接受它作为答案

标签: apache redirect nginx proxy cross-domain


【解决方案1】:

代理时不应包含 URI。请尝试以下操作:

proxy_pass http://10.1.200.156:‌​8080;

【讨论】:

    猜你喜欢
    • 2013-10-17
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 2021-02-04
    • 2012-05-09
    • 2018-05-06
    • 2014-12-05
    • 2018-01-07
    相关资源
    最近更新 更多