Nginx配置

Administrator
Administrator
发布于 2024-12-19 / 67 阅读
0

Nginx配置

利用宝塔部署在服务器

config文件配置

    location /prod-api/{
      proxy_pass  http://127.0.0.1:8085/;
    }

伪静态

    location / {
      try_files $uri $uri/ /index.html;
    }

手动配置在windows环境下

下载nginx

通过网盘分享的文件:nginx-1.24.0.zip

链接: https://pan.baidu.com/s/1J_JcS062-WM7_aYKwXaF3Q?pwd=6fjd 提取码: 6fjd

--来自百度网盘超级会员v5的分享

将dist包放在/html目录下

修改conf/nginx.conf文件

worker_processes  1;  # 根据 CPU 核心数调整

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;  # 监听 80 端口(HTTP)
        server_name  localhost;  # 域名或 IP,本地测试用 localhost

        location / {
            root   html/dist;  # 指向你的 dist 文件夹
            index  index.html index.htm;
            try_files $uri $uri/ /index.html;  # 单页应用(SPA)需要此配置,如Vue/React/Angular
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

启动/重启 Nginx​

  • 启动 Nginx​:双击 nginx.exe 或命令行运行:

    start nginx
  • 重启 Nginx​(修改配置后):

    nginx -s reload
  • 停止 Nginx​:

    nginx -s stop