返回之前Nginx auth

时间:2016-09-07 10:49:03

标签: nginx nginx-location

我正在使用nginx和auth。 所有auths在位置设置正常,但我有一个位置/马拉松,返回与其他端口相同的URL。我已将auth添加到此位置,但它不起作用。我认为是关于return指令,但我不知道为什么以及如何处理它或解决它。我一直在寻找,但我对此一无所知 任何想法为什么或如何处理它?<​​/ p>

user root;
worker_processes 4; # 2 per core

error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
use epoll;
}

http {

upstream mypelotweb {
    least_conn;

    server myweb.marathon.mesos:8001;
    server myweb.marathon.mesos:8002;
    server myweb.marathon.mesos:8003;
    server myweb.marathon.mesos:8004;
}

upstream mypelotwebsockets {
    least_conn;

    server myweb.marathon.mesos:8001;
    server myweb.marathon.mesos:8002;
    server myweb.marathon.mesos:8003;
    server myweb.marathon.mesos:8004;
}

upstream wingmantracker {
    least_conn;
    server mywing-tracker.marathon.mesos:8011;
    server mywing-tracker.marathon.mesos:8012;
}

upstream club {
    server club.marathon.mesos:5000;
}

upstream soccerint {
    server soccerint.marathon.mesos:5005;
}

upstream enet {
    server enet-web.marathon.mesos:5003;
}

map $http_upgrade $connection_upgrade {
    default upgrade;
    '' close;
}


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

log_format uri $request_uri;
access_log /var/log/nginx/access.log;

keepalive_timeout 65;
proxy_read_timeout 200;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
gzip on;
gzip_min_length 1000;
gzip_proxied any;
gzip_types text/plain text/html text/css text/xml
           application/x-javascript application/xml
           application/atom+xml text/javascript;
proxy_next_upstream error;



server {
server_name mytree.com;
    listen 80;
    error_log /var/log/nginx/errorhttp.log;
    access_log /var/log/nginx/accesshttp.log;
    return 301 https://$host$request_uri;

}

server {
server_name mytree.com;
    listen 443;
    error_log /var/log/nginx/errorhttps.log;
    access_log /var/log/nginx/accesshttps.log uri;
    ssl on;
    ssl_certificate /etc/nginx/ssl/server.crt;
    ssl_certificate_key /etc/nginx/ssl/server.key;


location / {
root /www/mytree;
    auth_basic "Restricted Access";
    auth_basic_user_file /etc/nginx/.htpasswd;
}

    location /mypelot {
        proxy_pass_header Server;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Scheme $scheme;
        proxy_pass http://mypelotweb;

        proxy_set_header 'Access-Control-Allow-Origin' '*';
        proxy_set_header 'Access-Control-Allow-Credentials' 'true';
        proxy_set_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE';
    }

    location ~* ^/mypelot$ {
        auth_basic "Restricted Access";
        auth_basic_user_file /etc/nginx/.htpasswd;
        proxy_pass_header Server;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Scheme $scheme;
        proxy_pass http://mypelotweb;

        proxy_set_header 'Access-Control-Allow-Origin' '*';
        proxy_set_header 'Access-Control-Allow-Credentials' 'true';
        proxy_set_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE';
    }

    location /mypelot/ws {
        proxy_pass http://mypelotwebsockets;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
    }

    location /wingmantracker {
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass http://wingmantracker;

        proxy_set_header 'Access-Control-Allow-Origin' '*';
        proxy_set_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE';
    }

location /club {
        proxy_pass http://club;

        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept, Authorization';

        add_header 'Access-Control-Allow-Credentials' 'true';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE';
    }

location /soccerint {
        proxy_pass http://soccerint;

        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept, Authorization';

        add_header 'Access-Control-Allow-Credentials' 'true';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE';
    }

location /enet {

        proxy_pass http://enet;

        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept, Authorization';

        add_header 'Access-Control-Allow-Credentials' 'true';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE';
    }

location /mypelot-messenger {
    return 301 http://mypelot-messenger.marathon.mesos:15672;
    }

location /mesos {
    return 301 http://mytree.com:5050;
    }

location /marathon {
    auth_basic "Restricted Access";
    auth_basic_user_file /etc/nginx/.htpasswd;
    return http://mytree.com:8080;
    }

location /jenkins {
    return 301 http://myserver.ovh.net:8082;
    }

location /jira {
    return 301 https://mymymy.atlassian.net;
    }

location /bitbucket {
    return 301 https://bitbucket.org/statistics/;
    }
location /confluence {
    return 301 https://stats.atlassian.net/wiki/;
    }
}

}

0 个答案:

没有答案