
Rocky8에 Apache와 PHP가 기본으로 설치되어 있더라도 FastAPI 애플리케이션을 함께 운영할 수 있습니다. 일반적인 방법은 FastAPI를 Uvicorn(또는 Gunicorn+Uvicorn 워커)으로 실행하고, Apache를 리버스 프록시로 설정하는 것입니다. 아래 단계별로 설명드립니다:
sudo dnf install python3 python3-pip python3-venv
mkdir /opt/myfastapi
cd /opt/myfastapi
python3 -m venv venv
source venv/bin/activate
pip install fastapi uvicorn
uvicorn app:app --host 127.0.0.1 --port 8000
<VirtualHost *:80>
ServerName fastapi.example.com
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:8000/
ProxyPassReverse / http://127.0.0.1:8000/
</VirtualHost>
sudo systemctl restart httpd
[Unit]
Description=FastAPI Application
After=network.target
[Service]
User=your_user
Group=your_group
WorkingDirectory=/opt/myfastapi
ExecStart=/opt/myfastapi/venv/bin/uvicorn app:app --host 127.0.0.1 --port 8000
Restart=always
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable fastapi.service
sudo systemctl start fastapi.service
이렇게 하면 Apache가 포트 80에서 들어오는 요청을 FastAPI 서버(포트 8000)로 전달하게 되어 기존 Apache+PHP 환경과 병행하여 FastAPI 애플리케이션을 운영할 수 있습니다.