Ngnix初步学习
Nginx下载与安装(Linux)
nginx下载
1.root用户下进入/usr/local/src
su root
cd /usr/local/src
2.下载nginx所需包
# nginx
wget http://nginx.org/download/nginx-1.10.2.tar.gz
# openssl
wget http://www.openssl.org/source/openssl-fips-2.0.10.tar.gz
# zlib
wget http://zlib.net/zlib-1.2.11.tar.gz
# pcre
wget https://netix.dl.sourceforge.net/project/pcre/pcre/8.40/pcre-8.40.tar.gz
3.检查安装gcc
# 安装gcc
sudo apt-get install gcc
# 查看版本
gcc --version
4.安装编译所需文件(pcre、openssl、zlib、nginx)
cd openssl-fips-2.0.10
./config && make && make install
cd zlib-1.2.11
./configure && make && make install
cd pcre-8.40
./configure && make && make install
cd nginx-1.10.2
./configure --prefix=/usr/local/nginx && make && make install
--prefix=/usr/local/nginx : 将相关文件保存到一个文件夹下,方便管理
注意:如果在执行nginx包make编译过程中出现如下问题
cc1: all warnings being treated as errors
objs/Makefile:440: recipe for target 'objs/src/core/ngx_murmurhash.o' failed
解决方法
到对应的nginx目录下的objs/,将Makefile中的-Werror去除即可
-Werror:含义是将警告作为error,从而报错
5.运行nginx
root权限下,在/usr/local/nginx/sbin目录下执行
./nginx
非root用户
su ./nginx
查看运行状态
ps -aux | grep nginx
root 22187 0.0 0.0 29176 568 ? Ss 13:34 0:00 nginx: master process ./nginx
nobody 22188 0.0 0.0 33976 3252 ? S 13:34 0:00 nginx: worker process
root 22203 0.0 0.0 16180 1004 pts/2 S+ 13:34 0:00 grep --color=auto nginx
访问localhost出现welcome nginx即为成功
6.nginx 常用命令
/usr/local/nginx/sbin下
1.查看帮助
./nginx -h
2.重载或停止
/nginx -s stop, quit, reopen, reload
7.外网访问
1.修改/usr/local/nginx/conf/nginx.conf
在http标签中添加
server {
listen 80;
server_name nginx.test.com;
location / {
root html;
index index.html index.htm;
}
}
2.重启nginx服务
./nginx -s reload
3.其他主机访问
(1)直接访问开启nginx的ip
(2)在对应主机的host下面添加相应配置实现访问域名
ip nginx.test.com
注意:开启nginx服务的机器是否开启防火墙,需在防火墙关闭的情况下实现
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY