nginx部署前端项目完整步骤

官网下载对应版本 nginx: download

我下载的是这个版本

 下载的是一个压缩包,需要解压。解压后文件夹里应该是下面这些:

html文件夹里存放前端打包的文件,如下图:

 

配置 nginx.conf (用记事本打开该文件)

需要修改的地方是端口和文件地址 

配置完之后,双击打开nginx。在浏览器输入http://localhost:8889 ,就能看到前端项目。

 

 

下面是 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       8889;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html/dist;
            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;
    #    }
    #}

}

ps:发给其他人使用,直接打包nginx。对方解压后双击exe文件,在浏览器输入地址打开即可浏览。

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Nginx部署前端项目,你可以按照以下步骤操作: 1. 首先,确保你已经安装了Nginx。你可以从官方网站或使用包管理器进行安装。 2. 将前端项目的构建文件(通常是一个包含静态资源的文件夹,例如build或dist)拷贝到Nginx的默认站点目录下。在大多数Linux系统上,默认的站点目录是`/var/www/html`。 3. 打开Nginx的配置文件,通常位于`/etc/nginx/nginx.conf`。你可以使用任何文本编辑器打开它。 4. 在配置文件中找到`server`块,该块定义了Nginx的虚拟主机配置。 5. 在`server`块内部,添加一个新的`location`块,用于指定前端项目的路径和配置。 例如,如果你的前端项目在域名的根目录下,你可以将以下配置添加到`location`块中: ``` location / { root /var/www/html/build; # 替换为你实际的前端项目路径 index index.html; } ``` 如果你的前端项目在子路径下,你需要相应地更改`location`块中的路径和根目录。 6. 保存并关闭配置文件。 7. 重新加载Nginx配置,以使更改生效。你可以使用以下命令重新加载Nginx: ``` sudo nginx -s reload ``` 如果你使用的是不同的操作系统或包管理器,可能需要使用不同的命令重新加载Nginx。 8. 现在,你应该能够通过访问Nginx服务器的IP地址或域名来查看部署前端项目。 请注意,这只是一个基本的配置示例,实际配置可能会因前端项目的要求而有所不同。你可能需要进一步调整Nginx的配置以满足你的需求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值