我在一台装有 github ci/cd 的 ubuntu 服务器上有一个 dockerized node js 应用程序,并且我已经用 nginx 设置了反向代理,当我点击 serverip 时它可以工作,但是当我执行诸如 serverip/aboutpage 之类的操作时
我在带有 github ci/cd 的 ubuntu 服务器上有一个 dockerized node js 应用程序,并且我已经使用 nginx 设置了反向代理,当我访问 serverip 时它可以工作,但是当我执行诸如 serverip/aboutpage 之类的操作时,nginx 返回 404,因此我尝试使用 curl 0.0.0.0:8080/aboutpage 访问我服务器上的 docker 容器,它返回了一个有效的响应
这是 etc/nginx/sites-available 下的默认文件
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
proxy_pass http://172.17.0.2:8080; #docker container ip
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
Dockerfile
FROM node:22-alpine
RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app
USER node
WORKDIR /home/node/app
COPY --chown=node:node package*.json .
RUN npm install
COPY --chown=node:node . .
EXPOSE 8080
CMD [ "node", "server.js" ]
ci.yml
name: CI Pipeline
on:
push:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Login Dockerhub
env:
DOCKER_USERNAME: ${{secrets.DOCKER_USERNAME}}
DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}}
run: docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
- name: Build the Docker image
run: docker build -t sm-api .
- name: Tag Docker local image
run: docker tag sm-api username/sm-api:latest
- name: Push to Dockerhub
run: docker push username/sm-api:latest
cd.yml
name: CD Pipeline
on:
workflow_run:
workflows: ["CI Pipeline"]
types:
- completed
jobs:
build:
runs-on: self-hosted
steps:
- name: Pull Docker image
run: sudo docker pull username/sm-api:latest
- name: Delete Old docker container
run: sudo docker rm -f sm-api-container || true
- name: Run Docker Container
run: sudo docker run -d -p 8080:8080 --name sm-api-container username/sm-api
我的 nodejs 路由器索引文件
function MyRoutes(app, express){
const router = express.Router();
router.get('/', (req, res) => {
res.send('HomePage');
});
router.get('/about', (req, res) => {
res.send('about');
});
return router;
}
module.exports = {
WebRoutes
};
本地一切正常
假设球体位于位置 [0,0](目前),我使用这种方法来计算球体表面上具有一定半径的点,给定纬度/经度坐标(Vector2 x/y):pub...
假设球体位于位置 [0,0](目前),我使用这种方法根据纬度/经度坐标(Vector2 x/y)计算球体表面上具有一定半径的点:
public static Vector3 GetPointOnSphere(Vector2 coo, float radius)
{
float lati = coo.x * Mathf.Deg2Rad;
float longi = coo.y * Mathf.Deg2Rad;
float x = radius * Mathf.Cos(lati) * Mathf.Cos(longi);
float y = radius * Mathf.Cos(lati) * Mathf.Sin(longi);
float z = radius * Mathf.Sin(lati);
return new Vector3(x, y, z);
}
将其翻译如下:
public static Vector2 GetCoords(Vector3 point, float radius)
{
float lati = Mathf.Asin(point.z / radius) * Mathf.Rad2Deg;
float longi = Mathf.Atan2(point.y, point.x) * Mathf.Rad2Deg;
return new Vector2(lati, longi);
}
我通过相机的光线投射获取表面点,并使用它将球体周围的物体移动到目标坐标:
bool MoveTowardsPoint(Vector2 target, float stop_dist)
{
Vector2 curr = GetCoords();
if (CompareVector2(curr, target, stop_dist))
{
return true;
}
double angularDistance = Math.Acos(Math.Sin(curr.x * Math.PI / 180) * Math.Sin(target.x * Math.PI / 180) +
Math.Cos(curr.x * Math.PI / 180) * Math.Cos(target.x * Math.PI / 180) *
Math.Cos(Math.Abs(curr.y - target.y) * Math.PI / 180)) + 1e-6;
double fr = MoveSpeed * Time.fixedDeltaTime / angularDistance;
Vector2 coords = new Vector2(LerpAngle(curr.x, target.x, fr),
LerpAngle(curr.y, target.y, fr));
transform.position = GetPointOnSphere(coords);
return false;
}
它在球体的某些部分起作用,但我认为在“水平极点”附近,当“fr”增长到无穷大时(尝试过将其限制,但并没有解决核心问题),目标永远无法达到,看起来棋子被迫远离这些极点。该区域相当大,位于地球的两侧。我该怎么办?
MoveTowardsPoint 中使用的方法:
float LerpAngle(double a, double b, double t)
{
double delta = Repeat((b - a), 360);
if (delta > 180)
delta -= 360;
return (float)(a + delta * Clamp01(t));
}
double Repeat(double t, double length)
{
return Clamp(t - Math.Floor(t / length) * length, 0.0f, length);
}
double Clamp(double value, double min, double max)
{
if (value < min) return min;
if (value > max) return max;
return value;
}
double Clamp01(double value)
{
if (value < 0.0) return 0.0;
if (value > 1.0) return 1.0;
return value;
}