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
我想大声告诉你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
黄舟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
}
大家讲道理2017-05-16 17:18:59
You don’t need a proxy, just rewrite the url rewrite ^/(.*)$ http://url.com:9000/$1 permanent;