当前第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怎样打开目录浏览功能
nginx怎么增加ssl模块
系统提示找不到nginx命令怎么办
centos系统下nginx启动不了怎么办
如何仅在nginx web服务器中启用tls1.2
linux中如何设置nginx开机自启
停止nginx服务的方法有哪些
nginx相对于apache来说有什么优势
更多相关阅读请进入《nginx》频道 >>
转载请注明出处:木庄网络博客 » nginx如何实现端口转发