3

I don't see what the problem is with this NGINX server configuration. I'm running a tomcat server on port 8081, jboss on 8080, and have NGINX listening on port 80. I'm sending an ajax request to port 80 and would like to have it proxy_pass to the jboss server. The webapp is running on port 8081 and the request is being sent to port 80:

server {
    listen 80;
    server_name example1.com;
    root /home/login/users1;
    access_log /home/nginx/example1/log/access.log;
    error_log /home/nginx/example1/log/error.log;
    location /login {
         add_header 'Access-Control-Allow-Origin' '*';
         add_header 'Access-Control-Allow-Credentials' 'true';
         add_header 'Access-Control-Allow-Headers' 'Content-Type,Accept';
         add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE';

         proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
         proxy_redirect off;
         proxy_buffering off;
         proxy_set_header        Host            $host;
         proxy_set_header        X-Real-IP       $remote_addr;
         proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
         proxy_pass http://192.168.xx.xxx:8080/path/to/api/user/login;

    }
}

The console output is:

OPTIONS http://192.168.xx.xxx/home/login/users1 405 (Not Allowed) jquery.js:8102
XMLHttpRequest cannot load http://192.168.xx.xxx/home/login/users1. Origin http://192.168.xx.xxx:8081 is not allowed by Access-Control-Allow-Origin.

The AJAX request:

$.ajax( {
    url : 'http://192.168.xx.xxx/home/login/users1/login',
    type : 'post',
    contentType : 'application/json',
    success : function(data) {
    args.success(data);
    },
    data : args.data,
    error : args.error,
    crossDomain: true
});

I've looked at this similar post but I don't see the problem as I'm setting add_header 'Access-Control-Allow-Origin' '*'; Any ideas?

Thanks,

J

neridaj
  • 131
  • 1
  • 3

0 Answers0