在nginx启动后,于/etc/nginx/conf.d/中,修改default.conf文件
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://IP:端口;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
将上的proxy_pass的内容改为需要转发的目标。这样对nginx监听的端口(这里是80)的访问就会抓发给目标地址。
若要监听多个端口,直接在文件中生成多个server描述即可
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://IP:端口;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
server {
listen 81;
server_name localhost;
location / {
proxy_pass http://IP:端口;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
server {
listen 82;
server_name localhost;
location / {
proxy_pass http://IP:端口;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}