zoukankan      html  css  js  c++  java
  • nginx 安装部署前端项目

    只进行最简单的部署,后期若有所学习会完善文档。

    1. 安装nginx

    apt install nginx
    

      安装完之后会在  /etc 下有nginx 文件, 里边包含相关配置

      启动nginx

      

    start nginx
    

      使用你的浏览器访问服务器ip, 会出现nginx 的界面

    2. 配置nginx.conf 文件主要就是指明项目文件以及mime.types

      注意: 安装完之后有可能出现 没有 nginx.conf 文件, 也没有 mime.types 文件自己创建即可

    vim /etc/nginx/nginx.conf

      我是做测试用的所以搭建的比较简单,内容如下, 如果,你没有nginx.conf 可以粘过去改,当然也可以去看下其他人的

    #user  nginx;
    worker_processes  1;
    
    #error_log  log/error.log;
    #error_log  log/error.log  notice;
    #error_log  log/error.log  info;
    
    #pid        log/nginx.pid;
    
    error_log log/error.log debug;
    events {
        worker_connections  1024;
    }
    
    
    http {
         include       mime.types;
        # default_type  application/octet-stream;
        default_type text/plain;
    
        #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        off;
        #tcp_nopush     on;
    
        #keepalive_timeout  0;
        keepalive_timeout  65;
    
        #gzip  on;
    server {
            listen       8080;
            server_name  127.0.0.1;
    
            #charset koi8-r;
    
            #access_log  logs/host.access.log  main;
                    root   /home/admin/layuimini-2;
            index  page/login-3.html;
    
            #location / {
            #                  }
    
            #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;
        #    }
        #}
    
    }
    

      主要需要配置的内容介绍

    http {
         include       mime.types; # 这个主要是引入文件时指明类型的, 我的没有,所以自己创建了一个
        # default_type  application/octet-stream;
        default_type text/plain;  # 当没有指明mime.types 的时候默认使用
    
        #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  127.0.0.1; # 指明域名/ip, 很多人使用 _ 或 _* 来代替。
    
            #charset koi8-r;
    
            #access_log  logs/host.access.log  main;
            root   /home/admin/layuimini-2;  # 指明项目文件根目录
            index  page/login-3.html;  # 指明首页, 默认问 设置的 root 下的 index.html, 在这里我指明了我的登录页面
    
            location / {
                              }
    

      mime.types 内容如下:

    types {
        text/html html;  # 后缀名为 .html 的为 text/html
        text/html conf;
        image/gif gif;
        image/jpeg jpg;
        text/css  css;
    
    }
    

      注: 分别指明各种文件的类型, 最开始我没有指明的时候,我的 css 样式没有生效,一种方式是将html 中的 <!DOCTYPE html> 删掉, 但明显这样不合法, 所以加上了mime.types 配置。

    3. 配置完后使用 nginx -s reload 重启nginx

        访问你服务器的 ip:端口 即可, 他会默认指向配置的界面

      

  • 相关阅读:
    java中Annotation注解的定义与使用
    ABC184 D——F && 一道LC好题
    YZYのPython 作业~
    杂谈(11.13——lca && mst)
    树状数组(BIT)—— 一篇就够了
    Codeforces Round #673 (Div. 2)[A-E]
    Codeforces Round #674 (Div. 3)
    Educational Codeforces Round 95 (Rated for Div. 2) [A -- E]
    LEETCODE 第 205 场周赛
    Codeforces Round #662 (Div. 2)
  • 原文地址:https://www.cnblogs.com/ShanCe/p/14172578.html
Copyright © 2011-2022 走看看