Nginx安装
转载自:https://www.cnblogs.com/liujuncm5/p/6713784.html
一:依赖环境
1:添加gcc环境
yum install gcc-c++
2:PCRE pcre-devel
yum install -y pcre pcre-devel
3:zlib
yum install -y zlib zlib-devel
4:OpenSSL
yum install -y openssl openssl-devel
二:下载安装包
1:官网
https://nginx.org/en/download.html
2:wget
yum install wget -- 如果wget已安装可忽略该步骤
wget -c https://nginx.org/download/nginx-1.12.0.tar.gz
三:安装
1:解压 + 进入解压后的目录
tar -zxvf nginx-1.12.0.tar.gz
cd nginx-1.12.0
2:配置(使用默认配置)
./configure
3:编译
make
4:安装
make install
5:设置开机启动
echo "/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf" >> /etc/rc.local
6:备注说明
1:编译+安装完成后,nginx默认在 /usr/local/nginx 目录下
2:配置文件在 /usr/local/nginx/conf/nginx.conf
3:启动命令在 /usr/local/nginx/sbin/nginx
4:命令列表
cd /usr/local/nginx/sbin/
./nginx
./nginx -s stop
./nginx -s quit
./nginx -s reload
5:修改配置后,执行 reload 才能生效(nginx可在运行状态下执行reload)
三:配置文件服务器
1:选定文件夹(/data/uploadFile为例)
文件夹赋权限
chmod -R 755 /data/uploadFile
2:修改nginx.conf配置
vi /usr/local/nginx/conf/nginx.conf
user root; #启动nginx的用户
worker_processes 2; #与cpu核数一致即可
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
autoindex on; #显示目录(关闭off,下同)
autoindex_exact_size on; #显示文件大小
autoindex_localtime on; #显示文件时间
server {
listen 8010; #端口号
server_name localhost; #主机,默认localhost即可
location / {
root /data/uploadFile/;
# /data/uploadFile/ 目录下一定要有index.html这个文件
# 复制一份nginx原生的过去即可,原生index.html绝对路径
# /usr/local/nginx/html/index.html
# cp /usr/local/nginx/html/index.html /data/uploadFile
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
3:reload后修改的配置生效
./nginx -s reload
4:网页访问(保证端口号已打开)
http://ip:port
网友评论