1

Im trying to setup a proxy on a subdir but cant make it work...

I want to proxy all requests in a subdir to another port

eg

http://domain.com/websocket/test.php => http://domain.com:8080/websocket/test.php

But cant make it work.. I have now tried to return 404 if a path matching /websocket is requested.. But that wont work either

What am I missing here?!

PHP files are executed as they should..

file structure

/test.php
/websocket/server.php
/websocket/test.php

All URL's are requested without problems, but /websocket/server.php and /websocket/test.php should return 404 (look in the nginx conf)

nginx

location / {
    try_files  $uri $uri/ =404;
}

location ~ \.php$ {
    include  /var/ini/nginx/fastcgi.conf;
    fastcgi_pass  php;
    fastcgi_index  index.php;
}

location /websocket {
    return 404;

    proxy_pass http://localhost:8080;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

1 Answer 1

1

There are various types of location block and rules as to their evaluation order. See this document for details.

The location ~ ... block is a regular expression type, that are evaluated in order but have a higher precedence than any prefix location (e.g. location /websocket).

If you want a prefix location to have higher precedence than the regular expression location blocks, either: - use the ^~ modifier, or - turn it into a regular expression block and order it first.

For example:

location ^~ /websocket { ... }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.