1.安装依赖包
apt update
apt-get install gcc
apt-get install libpcre3 libpcre3-dev
apt-get install zlib1g zlib1g-dev
apt-get install openssl
apt-get install libssl-dev
apt-get install gcc libpcre3 libpcre3-dev zlib1g zlib1g-dev openssl libssl-dev -y
2.下载nginx源码并解压
mkdir work
cd work
wget http://nginx.org/download/nginx-1.22.1.tar.gz
tar zxvf nginx-1.22.1.tar.gz
cd nginx-1.22.1
3.编译并安装
#prefix后面的路径是编译后安装nginx的路径
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
4.检查
cd /usr/local/nginx/sbin
./nginx -V
./nginx -t
5.设置开机自动启动
crontab -e
输入:
@reboot /usr/local/nginx/sbin/nginx
然后 reboot 重启服务器
6.配置
打开配置文件nginx.conf,路径为:/usr/local/nginx/conf/nginx.conf
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 37 38 39 40 41 42 43 44 | server { listen 80; server_name t1.xxx.net; location / { proxy_pass http: //localhost:50000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection keep-alive; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } } server{ listen 80; server_name t2.aaaa.com; rewrite ^(.*)$ https: //${server_name}$1 permanent; #设置http自动转发https } server { listen 443 ssl; server_name t2.aaaa.com; ssl_certificate /root/ssl/xxx.pem; ssl_certificate_key /root/ssl/xxx.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on ; location / { proxy_pass http: //localhost:50001; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection keep-alive; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } } |
7.常用命令
./nginx
./nginx -s reload
./nginx -s stop
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理