banner
NEWS LETTER

nginx&ubuntu 安装使用

Scroll down
1
部署环境:Ubuntu 22.04 LTS (GNU/Linux 5.15.0-94-generic x86_64)

1.安装

1
sudo apt-get install nginx # 默认配制放在 /etc/nginx/sites-enabled/default

2. 常用指令

1
2
3
4
5
6
7
8
9
sudo systemctl enable nginx.service # 开机自启动
sudo systemctl start nginx.service
sudo systemctl status nginx.service
sudo systemctl stop nginx.service
sudo systemctl restart nginx.service
sudo journalctl -fu nginx.service # 查看运行日志

sudo nginx -t # 查看nginx配制是否生效
sudo nginx -s stop | quit | reopen | reload # 常用指令

3. 配制代理

  • 前端
  • 后端:网关,单体应用
  • 直接上配制
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
server {
listen 80 default_server;
listen [::]:80 default_server;

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;

server_name _;

location ^~ /gateway/ {
proxy_pass http://localhost:20000/gateway/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forward-For $remote_addr;
}

location ^~ /oss/ {
proxy_pass http://localhost:20011/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forward-For $remote_addr;
}

location ^~ /ws/ {
proxy_pass http://localhost:20011/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forward-For $remote_addr;
proxy_http_version 1.1; # 必须设置为1.1以支持WebSocket
proxy_set_header Upgrade $http_upgrade; # 设置Upgrade头
proxy_set_header Connection "upgrade"; # 设置Connection头
}

location / { # Vue应用的访问路径; 如果需要配制前缀,例如 /web,需要在Vue应用打包时指定前缀,这样才能反向代理成功
root /home/ubuntu/web/dist;
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
}
}

你那么好看,应该会支持一下我吧~

其他文章
cover
ubuntu 配制
  • 24/09/20
  • 15:37
  • ubuntu
cover
shell脚本参数说明
  • 23/12/02
  • 14:12
  • shell
目录导航 置顶
  1. 1. 1.安装
  2. 2. 2. 常用指令
  3. 3. 3. 配制代理
请输入关键词进行搜索