Home  >  Q&A  >  body text

How to jump to url.com:9000 when accessing url.com under nginx (similar to 301 jump)

Desired result:

Visithttp://url.com Automatically jump the URL to http://url.com:9000, similar to the 301 jump, the address bar also Follow the changes.

Since the URL url.com does not exist, the host is written locally to point to the IP

Write the following content in nginx:

server {
    listen 80;
    server_name url.com;
    location / {
        proxy_pass http://url.com:9000;
    }
}

But when testing the nginx configuration file, it prompts:

$ sudo nginx -t
nginx: [emerg] host not found in upstream "seafile.sfdev.com" in /etc/nginx/sites-enabled/seafile.conf:5
nginx: configuration file /etc/nginx/nginx.conf test failed
给我你的怀抱给我你的怀抱2713 days ago591

reply all(4)I'll reply

  • 我想大声告诉你

    我想大声告诉你2017-05-16 17:18:59

        if ($host ~* url.com) {
            rewrite ^/(.*)$ http://url.com:9000/ permanent;
        }

    Or choose directly:

    rewrite ^/(.*)$ http://url.com:9000/ permanent;

    If it is a direct jump, there is no need to add the location field, directly:

    server {
        listen 80;
        server_name url.com;
        rewrite ^/(.*)$ http://url.com:9000/ permanent;
    }

    The proxy_pass in your configuration file forwards the request to the proxy server. For details, please see here:
    http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass

    reply
    0
  • 黄舟

    黄舟2017-05-16 17:18:59

    server {
        listen 80;
        server_name url.com;
        rewrite ^(.*) http://$server_name:9000$1 permanent;
    }
    server {
        listen 9000;
        server_name url.com;
        # other
    }

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-16 17:18:59

    Try it rewrite ^ url redirect

    reply
    0
  • 大家讲道理

    大家讲道理2017-05-16 17:18:59

    You don’t need a proxy, just rewrite the url rewrite ^/(.*)$ http://url.com:9000/$1 permanent;

    reply
    0
  • Cancelreply