Nginx configuration realizes proxy multiple intranet addresses

Source: Internet
Author: User

On the internet to see an example, if the network configuration, but if the page contains a local picture (if the URL to refer to the image will not be a problem), will cause the page can not be displayed normally.

The following is an example based on the red part of the modification:

Suppose there are multiple addresses in the intranet, such as:

Http://192.168.10.1/manage
Http://192.168.10.2/manage2

There is an external public network address 100.100.112.121, want to implement the request:

Visit 100.100.112.121/bbsadmin to access Http://192.168.10.1/manage
Visit 100.100.112.121/cmsadmin to access Http://192.168.10.1/manage2


The configuration is as follows:

server {
Listen 5000;
server_name 127.0.0.1;
CharSet Utf-8;

Location/{
root HTML;
Index index.html index.htm;
}

Error_page 404/404.html;

# REDIRECT Server error pages to the static page/50x.html
Error_page 502 503 504/50x.html;
Location =/50x.html {
root HTML;
}

Description: If the Site page contains a local picture, through Nginx may appear, this time need in the Server configuration section (Note that the current settings Agent server.) Make a mistake today, write this configuration section in the Server Configuration section of Nginx's own port) setting:

location ~* \. (css|js|jpg|bng|html|css|png|gif|ico|) $ {
Root D:/nodejs/nodejs project; #静态文件保存目录的上一级父目录
Expires 24h; #设置过期时间

Location/bbsadmin {
Proxy_pass Http://192.168.10.1/manage;
Proxy_redirect off;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header Host $http _host;
}


location/cmsadmin{
Proxy_pass Http://192.168.10.1/manage2;
Proxy_redirect off;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header Host $http _host;

}

}

Root Path
In server: Represents the global, meaning for all of the location.
In Location: local resource definition
location/a/{
root/var/www/;
}
Location/On behalf of the root in the location, if the root in location is not defined, it inherits from the server.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.