2301_81230941 2025-06-22 11:05 采纳率: 50%
浏览 10
已结题

Nginx怎么切换我要用的前端文件

问题遇到的现象和发生背景

我将前端代码已经放在了Nginx html目录里面了

img

img

img

但是出现了问题 输入localhost:90 打开的还是我之前的前端文件(我已经将nginx删了重新下载了)
这里是nginx 里的配置文件nginx.conf



#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       90;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   C:\nginx-1.28.0\html\sky;
            index  C:\nginx-1.28.0\html\sky\index.html;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

  • 写回答

4条回答 默认 最新

  • 宝码香车 优质创作者: JavaScript技术领域 2025-06-22 11:07
    关注

    让【宝码香车】来帮你解答,本回答参考DeepSeek编写,并整理提供。

    如果还有疑问可以点击头像关注私信或评论。如果答案让您满意,请采纳、点赞、关注,非常感谢!

    若您愿意支持,欢迎直接打赏,将不胜感激!
    .

    Nginx 前端文件切换指南

    根据您的问题描述,您想要切换 Nginx 服务的前端文件,但访问 localhost:90 仍然显示旧的前端内容。以下是解决方案:

    问题分析

    1. 您已经将新前端文件放在 C:\nginx-1.28.0\html\sky 目录下
    2. 配置文件中已经设置了正确的路径:
    location / {
        root   C:\nginx-1.28.0\html\sky;
        index  C:\nginx-1.28.0\html\sky\index.html;
    }
    
    1. 问题可能出在缓存或 Nginx 服务未正确重启

    解决方案

    1. 确认文件路径

    首先确认您的文件确实位于正确位置:

    • 检查 C:\nginx-1.28.0\html\sky 目录下是否有 index.html 文件
    • 确保文件权限允许 Nginx 读取

    2. 清除浏览器缓存

    浏览器可能缓存了旧的前端文件:

    • Ctrl+Shift+Delete 清除浏览器缓存
    • 或使用隐私模式访问 localhost:90

    3. 正确重启 Nginx 服务

    修改配置后需要正确重启 Nginx:

    # 停止 Nginx
    nginx -s stop
    
    
    # 启动 Nginx
    start nginx
    

    或者使用任务管理器确保所有 nginx.exe 进程已结束,然后重新启动。

    4. 检查配置文件语法

    验证配置文件是否有语法错误:

    nginx -t
    

    5. 检查端口占用

    确认端口 90 没有被其他服务占用:

    netstat -ano | findstr :90
    

    6. 简化配置建议

    可以简化您的配置为:

    location / {
        root   html/sky;
        index  index.html;
    }
    

    完整排查流程

    "开始"

    错误日志检查

    取消注释并检查错误日志:

    error_log  logs/error.log;
    

    然后查看 logs/error.log 文件获取具体错误信息。

    总结

    1. 确认文件位置正确
    2. 清除浏览器缓存
    3. 完全重启 Nginx 服务
    4. 检查端口占用
    5. 查看错误日志定位问题

    如果按照以上步骤操作后问题仍然存在,请提供错误日志内容以便进一步分析。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 6月22日
  • 已采纳回答 6月22日
  • 创建了问题 6月22日