1.yum安装最新版Nginx源
rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
安装Nginx
yum install -y nginx
Nginx默认目录
whereis nginx
nginx: /usr/sbin/nginx /usr/lib64/nginx /etc/nginx /usr/share/nginx
以下是Nginx的默认路径:
(1) Nginx配置路径:/etc/nginx/
(2) PID目录:/var/run/nginx.pid
(3) 错误日志:/var/log/nginx/error.log
(4) 访问日志:/var/log/nginx/access.log
(5) 默认站点目录:/usr/share/nginx/html
事实上,只需知道Nginx配置路径,其他路径均可在/etc/nginx/nginx.conf 以及/etc/nginx/conf.d/default.conf 中查询到。
常用命令
(1) 启动:
nginx
(2) 测试Nginx配置是否正确:
nginx -t
(3) 优雅重启:
nginx -s reload
(4) 停止:
nginx -s stop
2. centos7.5 1804 编译安装nginx方法
安装依赖软件包集合
yum install openssl openssl-devel pcre pcre-devel -y
rpm -qa openssl openssl-devel pcre pcre-devel
安装nginx软件包命令集合
mkdir -p /application /tools
cd /tools
wget -q http://nginx.org/download/nginx-1.16.0.tar.gz
tar -zxvf nginx-1.16.0.tar.gz
useradd -s /sbin/nologin -M nginx
cd nginx-1.16.0
./configure --user=nginx --group=nginx --prefix=/application/nginx-1.16.0 --with-http_ssl_module --with-http_stub_status_module --with-http_flv_module --http-fastcgi-temp-path=/application/nginx-1.16.0/nginx/fcgi
#比较全的编译配置
-------------------------------------------------------------------------------------------------------------------
./configure ./configure --prefix=/usr --sbin-path=/usr/local/sbin/nginx --conf-path=/usr/local/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/usr/local/run/nginx/nginx.pid --lock-path=/usr/local/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/tem/nginx/client --http-proxy-temp-path=/var/tem/nginx/proxy --http-fastcgi-temp-path=/var/tem/nginx/fcgi --with-http_stub_status_module
-------------------------------------------------------------------------------------------------------------------
make
make install
ln -s /application/nginx-1.16.0 /application/nginx
#设置配置文件
cd /application/nginx/conf
cp nginx.conf nginx.conf.bak
egrep -v "#|^$" nginx.conf.bak >nginx.conf #去除#号开头和空行
#启动nginx
/application/nginx/sbin/nginx -t #有报错 mkdir nginx/fcgi
/application/nginx/sbin/nginx #启动完成80端口可以访问
- nginx安装完成
- 附录 nginx.conf基础配置文件
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
server {
listen 80;
server_name www.oldboy.com;
location / {
root html/www;
index index.html index.htm;
}
access_log logs/access_www.log main;
}
server {
listen 80;
server_name bbs.oldboy.com;
location / {
root html/bbs;
index index.html index.htm;
}
access_log logs/access_bbs.log main;
}
}
网友评论