Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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;
    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;


The console output is:

OPTIONS 405 (Not Allowed) jquery.js:8102
XMLHttpRequest cannot load Origin is not allowed by Access-Control-Allow-Origin.

The AJAX request:

$.ajax( {
    url : '',
    type : 'post',
    contentType : 'application/json',
    success : function(data) {
    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?



share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.