1. 添加用户
useradd nginx
echo nginx:nginx|chpasswd
2.解压安装包
mkdir -p /home/nginx/soft
cd /home/nginx/soft
tar -xvf nginx-1.12.1.tar.gz
tar -xvf openssl-1.1.0h.tar.gz
tar -xvf pcre-8.42.tar.gz
tar -xvf zlib-1.2.11.tar.gz
tar -xvf v0.61.tar.gz
tar xf openssl-1.0.1t.tar.gz
tar xf openssl-1.0.1t.tar.gz
tar xf perl-5.28.0.tar.gz
tar xf v0.61.tar.gz
tar xf pcre-8.39.tar.gz
tar -xvf luajit2-2.1-20190912.tar.gz
tar -xvf ngx_devel_kit-0.3.1.tar.gz
tar -xvf lua-nginx-module-0.10.14.tar.gz
unzip nginx_upstream_check_module-master.zip
yum install -y gcc gcc-c++
chown -R nginx:nginx /home/nginx/soft/*
chmod -R 755 /home/nginx/soft/*
3.使用root用户安装lua模块
cd /home/nginx/soft/luajit2-2.1-20190912
make
make install
4.添加变量
[root@redis02 ~]# echo "/usr/local/lib" >> /etc/ld.so.conf
[root@redis02 ~]# ldconfig
[root@redis02 ~]# vim /home/nginx/.bash_profile
export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/luajit-2.1
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
[root@redis02 ~]# source /home/nginx/.bash_profile
[root@redis02 ~]# chown -R nginx:nginx /home/nginx/soft/
5.使用nginx用户安装其他模块
[root@redis02 ~]# su - nginx
cd /home/nginx/soft/pcre-8.42
./configure --prefix=/home/nginx/pcre-8.42
make && make install
cd /home/nginx/soft/zlib-1.2.11
./configure --prefix=/home/nginx/zlib-1.2.11
make && make install
cd /home/nginx/soft/openssl-1.1.0h
./config --prefix=/home/nginx/openssl-1.1.0h
make && make install
cd /home/nginx/soft/nginx-1.12.1
./configure --prefix=/home/nginx/nginx-1.12.1 \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-pcre=/home/nginx/soft/pcre-8.42 \
--with-openssl=/home/nginx/soft/openssl-1.1.0h \
--with-zlib=/home/nginx/soft/zlib-1.2.11 \
--add-module=/home/nginx/soft/echo-nginx-module-0.61 \
--add-module=/home/nginx/soft/ngx_devel_kit-0.3.1
--add-module=/home/nginx/soft/lua-nginx-module-0.10.14
--add-module=/home/nginx/soft/nginx_upstream_check_module-master
make -j2
make install
5.报错解决
5.1 报错1
nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory
出现这个错误,是变量没有写进去,所以就添加下变量:
cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
echo “/usr/local/lib” >> /etc/ld.so.conf
ldconfig
然后就正常了。
可以去测试下:
修改nginx.conf配置文件
server加入:
location /hello {
default_type’text/plain’;
content_by_lua’ngx.say(“Hello Lua!”)’;
}
访问出现Hello Lua!提示就完全没问题了。
普通用户在restart和reload nginx时,会报错:
5.2 报错2
nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /usr/local/nginx/conf/nginx.conf:2
原因是:默认情况下Linux的 1024
以下端口是只有root用户才有权限占用
方法一
所有用户都可以运行(因为是755权限,文件所有者:root,组所有者:root)
chown root.root nginx
chmod 755 nginx
chmod u+s nginx
方法二
仅 root 用户和 wyq 用户可以运行(因为是750权限,文件所有者:root,组所有者:www)
chown root.www nginx
chmod 750 nginx
chmod u+s nginx
方法三
在sbin目录下使用管理员权限启动
sudo ./nginx
方法四
如果端口是大于1024的话,就注释掉 nginx.conf
中的 user root;
[root@redis02 ~]# cat /home/nginx/nginx-1.12.2/conf/nginx.conf
#user root;
worker_processes 1;
#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 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"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 8888;
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;
}
location /AssetWeb {
proxy_pass $scheme://172.16.131.31:7100$request_uri;
}
location /ucenter {
proxy_pass $scheme://172.16.131.31:8081$request_uri;
}
location /batch-xc {
proxy_pass $scheme://172.16.131.31:8000$request_uri;
}
location /batch-guar {
proxy_pass $scheme://172.16.131.133:8000$request_uri;
}
location /sms-web {
proxy_ignore_client_abort on;
proxy_pass $scheme://172.16.131.31:8000$request_uri;
}
#proxy_pass $scheme://172.16.131.49:8002$request_uri;
# }
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://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 {
# 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;
# 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;
# }
#}
}