当前位置: 首页 > article >正文

nginx部署前端项目

1.将打包后的前端文件放到nginx目录中,通常打包后的文件名都是dist,我这里用的web为例
在这里插入图片描述
2.修改 nginx.conf 中的 location 配置
文件位置:/opt/homebrew/etc/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       8080;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

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

        #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;
    #    }
    #}
    include servers/*;
}

http://www.kler.cn/a/519012.html

相关文章:

  • docker-compose篇---创建jupyter并可用sudo的创建方式
  • MySQL 基础学习(2): INSERT 操作
  • CLion入门2.0(优雅进行STM32和ESP32开发)(船新版本)
  • 【2025年数学建模美赛F题】(顶刊论文绘图)模型代码+论文
  • 将 OneLake 数据索引到 Elasticsearch - 第二部分
  • NX100 参数配置
  • 图片导入到ppt之后再打印就糊掉了如何解决?
  • AUTOSAR从入门到精通-【AUTOSAR】OS模块中的Alarm详解
  • spring cloud如何实现负载均衡
  • 【Paper Tips】随记2-word版快速删除某字符
  • Flutter:自定义Tab切换,订单列表页tab,tab吸顶
  • [STM32 标准库]定时器输出PWM配置流程 PWM模式解析
  • C++ 入门速通-第2章【黑马】
  • ASP.NET Core MVC
  • Kafka常见问题之Kafka 报错:org.apache.kafka.common.errors.NotLeaderOrFollowerException
  • 蓝桥杯例题二
  • ‌春节旅游高峰,人力资源如何巧妙应对?
  • 【C++】详细讲解继承(下)
  • 【Linux】进程地址空间与虚拟地址空间
  • OceanBase PolarDB 体系分析图 ---一段人生哲理 封箱2024