当前第2页 返回上一页
test.com/news/api,访问的是ip:8081/api;而如果代理服务器地址中是不带有URI的,则会用完整的请求URL来转发到代理服务器test.com/news/api,访问的是ip:8081/news/api。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | server {
listen 80;
# listen [::]:80 default_server;
server_name test.com
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
location /news{
proxy_pass http:test.com:8081/;
}
}
|
8081端口的配置: 与平时配置没什么差别
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | server {
listen 8081;
server_name localhost;
root /var/www/project;
location / {
index index.php index.html index.htm;
if ( !-e $request_filename){
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
}
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
#root /usr/share/ngixn/html;
#}
#我部署的是PHP项目,这里配置PHP解析
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
include /etc/nginx/fastcgi.conf;
}
}
|
以上就是nginx如何实现端口转发的详细内容,更多文章请关注木庄网络博客!
返回前面的内容
相关阅读 >>
nginx反向代理两个不同服务器
为什么会出现nginx
nginx如何端口复用
阿里slb和nginx的区别
nginx_lua能做什么
nginx源码是什么语言
iis跟nginx哪个好
linux服务器如何安装nginx
nginx如何启动脚本
nginx的三种反向代理方式你都知道么
更多相关阅读请进入《nginx》频道 >>
转载请注明出处:木庄网络博客 » nginx如何实现端口转发