角度重定向到同一主机上的后端应用程序

时间:2019-03-12 18:11:00

标签: django angular nginx redirect

我有一个应用程序,该应用程序的前端是Angular,后端是Django,位于同一主机的不同端口上,为了进行身份验证,我的userService.js中包含以下代码:

authenticateUser: function() {
                  return $window.location.href = 'https://myhost:backend_port/oidc/auth/request/'
            }, 

但是当我访问我的应用程序时,它提示我“无法获取/ oidc / auth / request /” 所以我认为前端应该在应该将其发送到后端时对其进行处理。

我是否需要在Nginx配置中为后端添加“位置”?这是我当前的配置:

    server {
    listen 9004;
    ssl on;
    ssl_certificate /etc/ssl/certs/chained.cer;
    ssl_certificate_key /etc/ssl/certs/key.key;
    error_page 497 https://$host:9004$request_uri;

    server_name myhost;
    error_log /var/log/nginx/error-9004.log error;
    client_max_body_size 2G;
    location / {
            proxy_pass https://myhost:3004;
    }

    location /static/ {
            root /path/to/backend/code;
    }

    location /media/ {
            root /path/to/media;
    }

    location /api {
            include uwsgi_params;
            uwsgi_pass unix:/run/uwsgi/myapp.sock;
    }

更新:

我尝试将以下内容添加到我的nginx配置中:

   location /oidc {
           root /path/to/backend/code;
   }

现在我得到一个404。但是它应该包含在我的urls.py中:

# openid requirement
url(r'^oidc/', include('oidc_rp.urls')),

这是oidc_rp.urls:

urlpatterns = [
url(r'^auth/request/$', views.OIDCAuthRequestView.as_view(), name='oidc_auth_request'),
url(r'^auth/cb/$', views.OIDCAuthCallbackView.as_view(), name='oidc_auth_callback'),
url(r'^end-session/$', views.OIDCEndSessionView.as_view(), name='oidc_end_session'),
]

更新2:

角度前端在pm2上运行

0 个答案:

没有答案