Linux系统下安装配置 Nginx
Windows Nginx
https://nginx.org/en/download.html
Linux Nginx
https://nginx.org/download/nginx-1.24.0.tar.gz
解压
tar -zxvf tar -zxvf nginx-1.18.0.tar.gz #解压
安装依赖(如未安装)
yum groupinstall "Development Tools" -y
yum install -y pcre pcre-devel zlib zlib-devel openssl openssl-devel3. 启动 nginx
/usr/local/nginx/sbin/nginx验证是否启动成功
ps -ef | grep nginx5. nginx 安装后的目录结构(默认)
目录路径 说明
/usr/local/nginx/sbin/nginx 主程序
/usr/local/nginx/conf/ 配置文件,如 nginx.conf
/usr/local/nginx/html/ 默认网页根目录
/usr/local/nginx/logs/ 日志目录
worker_processes 1;events {worker_connections 1024;
}http {include mime.types;default_type application/octet-stream;sendfile on;keepalive_timeout 65;server {listen 8080;server_name _;root /usr/local/nginx/dist; # 你的前端打包目录index index.html index.htm;location / {try_files $uri $uri/ /index.html; # SPA 路由支持}location /api/ {proxy_pass http://localhost:10006/; # 转发API请求到本地后端proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}error_log logs/error.log warn;access_log logs/access.log;}
}