How to jump to url.com:9000 when accessing url.com under nginx (similar to 301 jump)
给我你的怀抱
给我你的怀抱 2017-05-16 17:16:59
0
4
663

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
给我你的怀抱
给我你的怀抱

reply all(4)
我想大声告诉你
    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

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

Try it rewrite ^ url redirect

大家讲道理

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template