一、安装
1、下载pcre-8.41.tar.gz包,下载路径:ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
2、下载nginx,下载版本为nginx-1.12.1.tar.gz
3、解压上面下载的两个文件:tar -zxvf pcre-8.41.tar.gz
tar -zxvf nginx-1.12.1.tar.gz
4、编译并安装pcre
进入刚才解压后的pcre-8.41目录下,
先编译:
./configure安装:
make && make install
如果上面没有报错,并且使用命令可以查看到pcre版本,则表示已安装成功,查看版本命令:
pcre-config --version
5、编译安装nginx
进入刚才解压后的nginx-1.12.1目录下,
先编译:
./configure --with-http_stub_status_module --prefix=/usr/local/nginx-1.12.1
安装:make && make install
要是上面,没有报错,并且在/usr/local/目录下生成了nginx-1.12.1文件夹,则表示已经安装成功
注意:pcre若是在编译时,指定了路径,如使用:
./configure --prefix=/usr/local/pcre-8.4
则编译nginx时,需要添加pcre-8.4包的路径,如下:
./configure --with-http_stub_status_module --prefix=/usr/local/nginx-1.12.1 --with-pcre=/usr/local/pcre-8.4
其他部分和上面一样。
二、配置
#user nobody; worker_processes 4; 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; client_header_buffer_size 128m; server { listen 80; server_name 172.29.10.30; charset utf-8; #注意这里结尾处分号 #charset koi8-r; access_log logs/host.access.log main; location /zyk { proxy_pass http://172.29.10.19:8280; } #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 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; # } #} }
三、启动
修改完配置文件后,启动nginx,使用命令:
/usr/local/nginx-1.12.1/sbin/nginx
启动报如下错误:
如上图,使用如下语句,定位错误:
ldd $(which /usr/local/nginx-1.12.1/sbin/nginx)
或者使用
ldd /usr/local/nginx-1.12.1/sbin/nginx
显示libpcre.so.1 => not found
解决办法:
查看lib库并创建软链,语句如下:
ls /lib64/ |grep pcre
从上图可以看到将libpcre.so.1指向libpcre.so.0.0.1,创建软链如下:
ln -s /lib64/libpcre.so.0.0.1 /lib64/libpcre.so.1
在查看一下ldd /usr/local/nginx-1.12.1/sbin/nginx
在重启过程中又遇到nginx: [emerg] invalid number of arguments in "charset" directive in /usr/local/nginx-1.12.1/conf/nginx.conf:45这个错误,这个查看配置文件,发现在对应行数少了分号“;”
错误截图:
改为
在重启nginx没有问题了。
nginx常用命令总结:
启动:/usr/local/nginx-1.12.1/sbin/nginx
重启:/usr/local/nginx-1.12.1/sbin/nginx -s reload
停止:/usr/local/nginx-1.12.1/sbin/nginx -s stop
重新载入配置文件:/usr/local/nginx-1.12.1/sbin/nginx -s reload
检查配置文件的正确性:/usr/local/nginx-1.12.1/sbin/nginx -t