linux安装nginx
手动安装
官网下载倒数第二新的包:https://nginx.org/en/download.html
我这里下载的是:nginx-1.24.0.tar.gz
安装nginx需要很多的依赖,可以用该文章里面的检测依赖方式试试,反正是缺啥补啥好了(https://blog.csdn.net/weixin_40141628/article/details/137601683)
解压文件
tar -zxvf nginx-1.24.0.tar.gz
执行安装
进入到解压目录
cd nginx-1.24.0
执行安装
# --prfix 表示安装的路径
./configure --prefix=/usr/local --without-http_rewrite_module
执行编译初始化
make && make install
启动nginx
nginx
检测是否成功
# 下面的两个命令哪个都行
netstat -ntulp|grep 80
ps -ef|grep nginx
常用命令
# 启动
nginx
# 停止
nginx -s stop
# 重启
nginx -s reload
配置文件
# 我这里的配置文件在/usr/local/conf中
cd /usr/local/conf
docker安装
配置文件的位置对应docker-compose.yml文件中的映射位置: /etc/nginx/conf.d目录下
# operation
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
# html页面
listen 8015;
listen [::]:8015;
server_name 127.0.0.1:8015;
location / {
root /home/docker/nginx/web/screen;
index aaaa.html bbb.html cc.html dd.html ee.html;
}
}
server {
# 某个后端服务
listen 8014;
listen [::]:8014;
client_max_body_size 50m;
server_name 127.0.0.1:8014;
root /home/docker/nginx/web/;
index index.html index.htm;
location /freedom/demo/gateway/ {
proxy_pass http://xxx.xx.xx.xx:8999;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-NginX-Proxy true;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
# 这里配置单个代理跨域,跨域配置
add_header 'Access-Control-Allow-Origin' *;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' *;
add_header 'Access-Control-Allow-Headers' *;
}
}
docker-compose.yml文件
version: "3"
services:
nginx:
image: nginx
restart: always
container_name: nginx
privileged: true
ports:
- 80:80
- 4443:443
- 8014:8014
- 8001:8001
- 8003:8003
- 8015:8015
- 8013:8013
volumes:
- /etc/localtime:/etc/localtime:ro
- ./log:/var/log/nginx
- ./conf.d:/etc/nginx/conf.d
- ./web:/home/docker/nginx/web
network_mode: host
标签:set,header,nginx,html,proxy,docker,安装
From: https://www.cnblogs.com/xy20211005/p/18217438