【技术】前端小问题集锦

[服务器] 前端需要掌握的nginx服务器配置

2022-11-29  本文已影响0人  爱吐槽的小姐

1. 常用命令

 - 进入命令行模式:  vi 文件名 
 - 切换编辑模式: i
 - 退出编辑模式:esc
 - 保存退出::wq 

2. 常用操作

2.1 给同事添加服务器权限

1)拿到对方的 ssh publish key
2)登录服务器 ssh root@xxx.xxx.xxx.xxx
3)执行命令: vi ~/.ssh/authorized_keys
4)编辑打开的配置文件,将同事的publish key 添加进去
5)保存退出::wq

2.2 将文件从本地上传至服务器

例:scp -c ./test/* root@xxx.xxx.xxx.xxx:/var/www/aa
备注:将本地 test文件夹下的所有内容,复制到服务器的/var/www路径下的 aa文件夹

2.3 前端项目配置 xxx.conf 文件

server {
    listen 3100; #nginx服务监听端口,选一个不被占用的即可
    server_name 127.0.0.1;
    root /var/www/项目名;

    access_log /var/log/nginx/项目名.access.log; #当前项目的访问日志

    location / {
        try_files $uri $uri.html $uri.html/ $uri/ =404;
        etag on;
        index index.html;
    }
}

upstream 服务组名字 { # 
    server 127.0.0.1:3100 weight=5; # prod
}

server {
    listen 80;
    server_name 虚拟主机名;
    root /var/www/项目名;

    access_log /var/log/nginx/项目名.access.log;

    location / {
        proxy_pass http://服务组名字; #配置反向代理地址
    }
}

汉字部分都需要根据自己的项目实际配置进行替换。
access_log对应的log文件会自动生成, 使用前需要先在nginx.conf 中做相应的配置

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    # 配置开始
    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  /var/log/nginx/access.log  main;

    # 其他配置


}
上一篇下一篇

猜你喜欢

热点阅读