Linux源码包安装Nginx
Nginx 源码包安装
Nginx(“engine x”)是⼀款是由俄罗斯的程序设计师Igor Sysoev所开发⾼性能的 Web和反向代理 服务器,也是⼀个IMAP/POP3/SMTP 代理服务器。
Nginx 安装
系统平台:CentOS 64位。
⼀、安装编译⼯具及库⽂件
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
⼆、⾸先要安装 PCRE
PCRE 作⽤是让 Nginx ⽀持 Rewrite 功能。
cd /data/tool/
wget downloads.sourceforge/project/pcre/pcre/8.35/pcre-8.
2、解压安装包:
tar zxvf pcre-8.
3、进⼊安装包⽬录
cd pcre-8.35
4、编译安装
./configure
make&&make install
5、查看pcre版本
pcre-config --version
8.35
三、安装 Nginx
1、下载
cd /data/tool/
wget /download/nginx-1.20.
2、解压安装包
tar zxvf nginx-1.6.
3、进⼊安装包⽬录
cd nginx-1.6.2
4、编译安装
./configure --prefix=/data/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/data/tool/pcre-8.35
make&make install
5、查看nginx版本
/data/nginx/sbin/nginx -v
6、创建软连接
ln -s /data/nginx/sbin/nginx /usr/local/bin/nginx
到此,nginx安装完成。
Nginx 配置
创建 Nginx 运⾏使⽤的⽤户 www:
/usr/sbin/groupadd www
/usr/sbin/useradd -g www www
配置f ,将/data/nginx/f替换为以下内容
cat /data/nginx/f
user www www;# 设置运⾏⽤户
worker_processes 4;#设置值和CPU核⼼数⼀致
#error_log logs/error.log;
error_log logs/error.log notice;#⽇志位置和⽇志级别
#error_log logs/error.log info;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include pes;
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"';
access_log logs/access.log main;
client_max_body_size 1024m;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/conf.d/*.conf;#引⼊⾃定义 .conf⽂件
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_comp_level 7;
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif im age/png;
gzip_vary off;
gzip_disable "MSIE [1-6]\.";
#下⾯是server虚拟主机的配置
#下⾯是server虚拟主机的配置
server {
listen 80;#监听端⼝
server_name localhost;#域名
#charset koi8-r;
access_log logs/host.access.log main;
location / {
root html;#站点⽬录
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass 127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
linux离线安装nginx详细教程# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration #
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
检查配置⽂件f的正确性命令:nginx -t
启动 Nginx
Nginx 启动命令如下:
/data/nginx/sbin/nginx
ps -ef |grep nginx
访问站点
从浏览器访问我们配置的站点ip:
Nginx 其他命令
以下包含了 Nginx 常⽤的⼏个命令:nginx -s reload # 重新载⼊配置⽂件nginx -s reopen # 重启 Nginx
nginx -s stop # 停⽌ Nginx
nginx -h # 查看帮助
Nginx 设置开机启动
在/etc/init.d下创建⽂件nginx
vim /etc/init.d/nginx
设置配置⽂件
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: NGINX is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/f
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/rc.d/init.d/network
# Check that networking is up.
["$NETWORKING"="no"]&&exit 0
nginx="/data/nginx/sbin/nginx"# 修改成nginx执⾏程序的路径
prog=$(basename $nginx)
NGINX_CONF_FILE="/data/nginx/f"# 修改成nginx配置⽂件路径
[ -f /etc/sysconfig/nginx ]&&. /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs(){
# make required directories
user=`$nginx -V 2>&1 |grep"configure arguments:.*--user="|sed's/[^*]*--user=\([^ ]*\).*/\1/g' -` if[ -n "$user"];then
if[ -z "`grep $user /etc/passwd`"];then
useradd -M -s /bin/nologin $user
fi
options=`$nginx -V 2>&1 |grep'configure arguments:'`
for opt in$options;do
if[`echo $opt |grep'.*-temp-path'`];then
value=`echo $opt |cut -d "=" -f 2`
if[! -d "$value"];then
# echo "creating" $value
mkdir -p $value&&chown -R $user$value
fi
fi
done
fi
}
start(){
[ -x $nginx]||exit 5
[ -f $NGINX_CONF_FILE]||exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[$retval -eq 0 ]&&touch$lockfile
return$retval
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论