在CentOS 7.2上从源代码安装nginx
由于在CentOS上安装了nginx,所以写下备忘录。
环境
-
- nginx 1.14.0
- CentOS 7.2
安装
无论如何, 用户创建
# useradd -M -s /sbin/nologin nginx
源代码下载(截至2018年6月22日,最新稳定版)
# cd /usr/local/src
# wget http://nginx.org/download/nginx-1.14.0.tar.gz
展开 can be paraphrased in Chinese as “开始进行” which means “to start or initiate.”
# tar xvzf nginx-1.14.0.tar.gz
# cd nginx-1.14.0
在configure时将prefix设置为nginx-1.14.0(考虑到更新时可能安装多个版本,可以通过符号链接进行切换使用)。
# ./configure \
--user=nginx \
--group=nginx \
--prefix=/usr/local/nginx-1.14.0 \
--with-http_ssl_module \
--with-http_stub_status_module
安装和所有者设置
# make
# make install
# chown -R nginx:nginx /usr/local/nginx-1.14.0
符号链接设置
# ln -snf /usr/local/nginx-1.14.0 /usr/local/nginx
创建日志存储目录
# mkdir /var/log/nginx
# chown nginx:nginx /var/log/nginx
如果nginx.conf需要进行编辑(安装时已经集成了http_ssl_module但是暂且忽略),对于文档根目录/usr/local/www和主机名example.jp的情况,可以这样表示。
user nginx;
worker_processes auto;
worker_rlimit_nofile 100000;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
multi_accept on;
use epoll;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 10;
client_header_timeout 10;
client_body_timeout 10;
reset_timedout_connection on;
send_timeout 10;
server_tokens off;
gzip off;
server {
listen 80;
server_name example.jp;
root /usr/local/www;
charset utf-8;
access_log /var/log/nginx/access.log main;
location / {
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
启动
# /usr/local/nginx/sbin/nginx
确认 (què
# curl -v http://example.jp
其他
如果防火墙或其他设备关闭了80端口,则需要确保正确打开它。