1.解决依赖关系
yum install gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel openssl openssl-devel -y
2.下载源码包
wget -c https://nginx.org/download/nginx-1.12.0.tar.gz
3.解压缩源码包
tar -zxvf nginx-1.12.0
4.在当前路径下通过configure这个脚本文件执行,释放makefile,然后指定安装nginx的路径,以及开启模块功能ssl与状态模块功能
./configure --prefix=/opt/nginx1-12/ --with-http_ssl_module --with-http_stub_status_module
5.编译且编译安装
make && make install
6.在/opt/nginx1-12/ 安装好nginx的目录,找到一个sbin的文件夹,找到nginx的启动命令,然后启动nginx服务
1.检查nginx安装后的目录,ll /opt/nginx1-12
drwxr-xr-x 2 root root 333 12月 6 09:32 conf 配置文件存放的目录, nginx.conf这个文件就是nginx的主配置文件
drwxr-xr-x 2 root root 40 12月 6 09:32 html 存放网页根目录的文件夹,存放了index.html **.html **.gif **.jpg
drwxr-xr-x 2 root root 6 12月 6 09:32 logs 日志目录
drwxr-xr-x 2 root root 19 12月 6 09:32 sbin nginx启动脚本目录
7.更改nginx.conf
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
proxy_pass http://localhost:5000/;
proxy_redirect off;
proxy_set_header Host $http_post;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
8.
./sbin/nginx -s stop
./sbin/nginx -s reload #平滑重启(修改了nginx配置文件,不重启服务就加载配置且生效)
../sbin/nginx -t 检测nginx.conf 配置文件的语法正确性