修改端口

This commit is contained in:
小王 2024-09-13 10:03:52 +08:00
parent d02df5a043
commit 36d9ca2fcb
5 changed files with 13 additions and 11 deletions

4
.env
View File

@ -10,5 +10,5 @@ DB_CHARSET = utf8
DEFAULT_LANG = zh-cn DEFAULT_LANG = zh-cn
SERVER_ADDR = 192.168.1.161 SERVER_ADDR = 192.168.1.161:8000
SERVER_PORT = 8000 NACOS_ADDR = 192.168.1.105:8848

View File

@ -10,7 +10,7 @@ RUN set -eux \
VOLUME /var/www/html VOLUME /var/www/html
ENV NACOS_ADDR="192.168.1.105:8848" \ ENV NACOS_ADDR="192.168.1.105:8848" \
SERVER_ADDR="192.168.1.161:80" SERVER_ADDR="192.168.1.161:8000"
ADD run.sh /run.sh ADD run.sh /run.sh
ADD default.conf /etc/nginx/http.d/default.conf ADD default.conf /etc/nginx/http.d/default.conf

View File

@ -22,8 +22,7 @@ class Index
$file = request()->file('file'); $file = request()->file('file');
$trueName = $file->getOriginalName(); $trueName = $file->getOriginalName();
$serverIP = env('SERVER_ADDR', '192.168.1.161'); $serverIP = env('SERVER_ADDR', '192.168.1.161:8000');
$serverPort = env('SERVER_PORT', 8000);
// 组装保存路径 // 组装保存路径
$savename = \think\facade\Filesystem::disk('upload')->putFile('upload', $file); $savename = \think\facade\Filesystem::disk('upload')->putFile('upload', $file);
@ -34,7 +33,7 @@ class Index
'msg' => null, 'msg' => null,
'data' => [ 'data' => [
"name" => $trueName, "name" => $trueName,
"url" => 'http://' . $serverIP . ':' . $serverPort . '/' . $savename, "url" => 'http://' . $serverIP . '/' . $savename,
// "url" => 'http://192.168.1.105:8080/file/' . $savename, // "url" => 'http://192.168.1.105:8080/file/' . $savename,
] ]
]); ]);

View File

@ -8,12 +8,14 @@ server {
root /var/www/html/public; root /var/www/html/public;
index index.php index.html index.htm index.nginx-debian.html; index index.php index.html index.htm index.nginx-debian.html;
# 伪静态
location / { location / {
if (!-e $request_filename){ if (!-e $request_filename){
rewrite ^(.*)$ /index.php?s=$1 last; break; rewrite ^(.*)$ /index.php?s=$1 last; break;
} }
} }
# 请求转发
location ~ \.php$ { location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000; fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php; fastcgi_index index.php;

View File

@ -11,24 +11,25 @@ use think\Env;
// 读取环境变量 // 读取环境变量
$env = new Env(); $env = new Env();
$env->load(__DIR__ . '/.env'); $env->load(__DIR__ . '/.env');
$serverIP = $env->get('SERVER_ADDR', '192.168.1.161'); $serverAddr = $env->get('SERVER_ADDR', '192.168.1.161:8000');
$serverPort = $env->get('SERVER_PORT', 8000); $nacosAddr = $env->get('NACOS_ADDR', '192.168.1.105:8848');
$task = new Worker(); $task = new Worker();
// 定时触发邮件发送任务 // 定时触发邮件发送任务
// 开启多少个进程运行定时任务,注意业务是否在多进程有并发问题 // 开启多少个进程运行定时任务,注意业务是否在多进程有并发问题
$task->count = 1; $task->count = 1;
$task->onWorkerStart = function(Worker $task) use ($serverIP, $serverPort) $task->onWorkerStart = function(Worker $task) use ($serverAddr, $nacosAddr)
{ {
$client = new Client([ $client = new Client([
// nacos地址 // nacos地址
"base_uri" => "http://192.168.1.105:8848", "base_uri" => $nacosAddr,
"timeout" => 5 "timeout" => 5
]); ]);
// 每2.5秒执行一次 // 每2.5秒执行一次
Timer::add(5, function() use ($client, $serverIP, $serverPort) Timer::add(5, function() use ($client, $serverAddr)
{ {
list ($serverIP, $serverPort) = explode(':', $serverAddr);
$response = $client->request("put", "/nacos/v1/ns/instance/beat", [ $response = $client->request("put", "/nacos/v1/ns/instance/beat", [
"form_params" => [ "form_params" => [
"serviceName" => "zeroerroa-file", "serviceName" => "zeroerroa-file",