我在一台装有 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
};
本地一切正常
我有一段代码,可以生成一个球并将其扔向玩家注视的方向,稍后我想制作一个从库存中扔物品的系统,但是我遇到了多个问题......
我有一段代码,它可以生成一个球,然后把它扔向玩家注视的方向,稍后我想制作一个从库存中投掷物品的系统,但我在多人游戏中遇到了问题,因为游戏对象只能生成服务器,所以我使用 Rpc,但它会在投掷物体之前造成相当大的延迟(比如 0.5 秒)
有谁知道如何减少这种延迟吗?
感谢您的任何想法
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Netcode;
public class PlayerFunctions : NetworkBehaviour
{
public GameObject itemPrefab;
public float throwForce;
public Transform cameraPos;
public Transform itemSpawnPos;
private KeyCode throwKey = KeyCode.Q;
bool network = false;
public override void OnNetworkSpawn()
{
base.OnNetworkSpawn();
network = true;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(throwKey) && IsOwner)
{
ThrowServerRpc(itemSpawnPos.position, cameraPos.rotation);
}
else if(!network)
{
Throw();
}
}
[ServerRpc]
void ThrowServerRpc(Vector3 position, Quaternion rotation)
{
GameObject objectToThrow = Instantiate(itemPrefab, position, rotation);
var objectToThrowNetworkObject = objectToThrow.GetComponent<NetworkObject>();
objectToThrowNetworkObject.Spawn();
ThrowClientRpc(objectToThrowNetworkObject.NetworkObjectId);
}
[ClientRpc]
void ThrowClientRpc(ulong networkObjectId)
{
NetworkObject networkObject = NetworkManager.Singleton.SpawnManager.SpawnedObjects[networkObjectId];
if(networkObject != null)
{
Rigidbody itemRb = networkObject.GetComponent<Rigidbody>();
itemRb.AddForce(cameraPos.forward * throwForce, ForceMode.Force);
itemRb.AddForce(transform.up * 100, ForceMode.Force);
}
}
void Throw()
{
GameObject objectToThrow = Instantiate(itemPrefab, itemSpawnPos.position, cameraPos.rotation);
Rigidbody itemRb = objectToThrow.GetComponent<Rigidbody>();
itemRb.AddForce(cameraPos.forward * throwForce, ForceMode.Force);
itemRb.AddForce(transform.up * 100, ForceMode.Force);
}
}