美文网首页Angular 8
Angular 8 部署 ubuntu nginx

Angular 8 部署 ubuntu nginx

作者: bei6 | 来源:发表于2019-04-11 23:29 被阅读43次

安装 nginx

sudo apt-get install nginx
  • /usr/sbin/nginx 主程序
  • /etc/nginx 存放配置文件
  • /usr/share/nginx 静态文件
  • /var/log/nginx 日志

测试

打开 firefox 访问 localhost,看到下图代表成功安装了 nginx。

nginx 常用命令

  • sudo nginx : 启动服务
  • sudo nginx -s stop : 先查出 nginx 进程 id,然后使用 kill 命令强制杀掉进程
  • sudo nginx -s quit : 等待 nginx 进程处理任务完毕,然后再进行停止
  • sudo nginx -s reload : 重启服务

多端口部署

准备好两个发布好的 angular 站点, 比如下面是我的两个站点所在文件夹:

  • /home/bey/nginx/garden-sunflower
  • /home/bey/nginx/beychi

打开 /etc/nginx/nginx.conf 找到 http 代码块,在其尾部添加如下代码:

每个 server 表示一个站点。

  • listen 后面填写分配给站点的端口。
  • root 后面填写对应的站点文件夹路径。

其他的暂时用不到关注。

server {
    listen      8080;
    server_name localhost;
    location / {
        root /home/bey/nginx/garden-sunflower;
        index index.html index.html;
    }

    error_page 404                /;

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

server {
    listen      8081;
    server_name localhost;
    location / {
        root /home/bey/nginx/beychi;
        index index.html index.html;
    }

    error_page 404                /;

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

整个文件看起来是这样的:

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;

    server {
        listen      8080;
        server_name localhost;
        location / {
            root /home/bey/nginx/garden-sunflower;
            index index.html index.html;
        }

        error_page 404                /;

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

    server {
        listen      8081;
        server_name localhost;
        location / {
            root /home/bey/nginx/beychi;
            index index.html index.html;
        }

        error_page 404                /;

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


#mail {
#   # See sample authentication script at:
#   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#   # auth_http localhost/auth.php;
#   # pop3_capabilities "TOP" "USER";
#   # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#   server {
#       listen     localhost:110;
#       protocol   pop3;
#       proxy      on;
#   }
# 
#   server {
#       listen     localhost:143;
#       protocol   imap;
#       proxy      on;
#   }
#}

保存需要管理员的权限。

重启 nginx sudo nginx -s reload

测试

打开 firefox 分别访问:

相关文章

网友评论

    本文标题:Angular 8 部署 ubuntu nginx

    本文链接:https://www.haomeiwen.com/subject/idraiqtx.html