我在(windows)本地有個(gè)nginx服務(wù)器,應(yīng)用的訪(fǎng)問(wèn)地址是http://localhost:88
我在本地啟動(dòng)了一個(gè)webman的服務(wù)器,使用http://127.0.0.1:8787,可以正常訪(fǎng)問(wèn)
我想要將8787代理到:88這個(gè)應(yīng)用下,通過(guò)http://localhost:88/s 直接訪(fǎng)問(wèn) 8787下的所有應(yīng)用
例如 http://localhost:88/s/dir/create 轉(zhuǎn)發(fā)到 http:127.0.0.1:8787/dir/create 上
我參考了 官網(wǎng)上的【nginx代理】 http://m.wtbis.cn/doc/webman/others/nginx-proxy.html
upstream webman {
server 127.0.0.1:8787;
keepalive 10240;
}
server
{
listen 88;
server_name a.com;
index index.php index.html index.htm default.php default.htm default.html;
root d:/dev/proj;
#PHP-INFO-START
include php/74.conf;
#PHP-INFO-END
location /api2 {
alias d:/dev/proj/api2/;
index index.php index.html index.htm;
if (!-e $request_filename) {
rewrite ^ /api2/index.php last;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass 127.0.0.1:20074;
}
}
# 代理服務(wù)
location /s {
client_max_body_size 20M;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_pass http://webman;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
access_log D:/BtSoft/wwwlogs/a.com.log;
error_log D:/BtSoft/wwwlogs/a.com.error.log;
}
重啟服務(wù)后,訪(fǎng)問(wèn) http://localhost:88/s/dir/create 直接顯示 404的頁(yè)面
訪(fǎng)問(wèn)不成功
在瀏覽器上 直接訪(fǎng)問(wèn) http://127.0.0.1:87/dir/create 可以正常訪(fǎng)問(wèn)
是哪個(gè)配置出錯(cuò)了呢?
<?php
namespace app\controller;
use support\Request;
class Dir
{
public function create(Request $request)
{
$dir = $request->post('dir');
// mkdir($dir);
return json([ 'code'=> 0, 'dir' => $dir ]);
}
}
訪(fǎng)問(wèn) http://localhost:88/s/dir/create
,轉(zhuǎn)發(fā)給webman請(qǐng)求變成 http://localhost:8787/s/dir/create
,當(dāng)然404了。
感覺(jué)你應(yīng)該用nginx重寫(xiě)下url變成http://localhost:8787/dir/create
,再轉(zhuǎn)發(fā)到webman
server {
listen 80 ;
server_name web.net;
location / {
proxy_pass http://127.0.0.1:8787/;
}
error_log /home/wwwlogs/web.error.log;
}
這樣配置代理即可