Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行。本文先整理web服务器内容。
[root@LFTp-Svn01 soft]# wget http://nginx.org/download/nginx-1.10.2.tar.gz
--2016-11-14 17:30:20-- http://nginx.org/download/nginx-1.10.2.tar.gz
Connecting to 10.112.11.12:3128… connected.
Proxy request sent, awaiting response… 200 OK
Length: 910812 (889K) [application/octet-stream]
Saving to: “nginx-1.10.2.tar.gz”
100%[===================================================================================================================>] 910,812 627K/s in 1.4s
2016-11-14 17:30:22 (627 KB/s) - “nginx-1.10.2.tar.gz” saved [910812/910812]
[root@LFTp-Svn01 soft]# yum -y install pcre pcre-devel openssl openssl-devel gcc
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
Package pcre-7.8-7.el6.x86_64 already installed and latest version
Package pcre-devel-7.8-7.el6.x86_64 already installed and latest version
Package openssl-1.0.1e-42.el6_7.4.x86_64 already installed and latest version
Package openssl-devel-1.0.1e-42.el6_7.4.x86_64 already installed and latest version
Package gcc-4.4.7-16.el6.x86_64 already installed and latest version
Nothing to do
[root@LFTp-Svn01 soft]# tar -xf nginx-1.10.2.tar.gz
[root@LFTp-Svn01 soft]# cd nginx-1.10.2
[root@LFTp-Svn01 nginx-1.10.2]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre
…………………………………………………………………………………….
Configuration summary
using system PCRE library
using system OpenSSL library
md5: using OpenSSL library
sha1: using OpenSSL library
using system zlib library
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
备注:
--prefix #指定安装目录
--with-http_stub_status_module #stub_status监控模块
--with-http_ssl_module #ssl模块
--with-http_gzip_static_module #压缩传输模块
--with-pcre #pcre模块,nginx强依赖
[root@LFTp-Svn01 nginx-1.10.2]# make && make install
………………………………………………………………………..
cp conf/fastcgi_params \
'/usr/local/nginx/conf/fastcgi_params.default'
test -f '/usr/local/nginx/conf/fastcgi.conf' \
|| cp conf/fastcgi.conf '/usr/local/nginx/conf'
cp conf/fastcgi.conf '/usr/local/nginx/conf/fastcgi.conf.default'
test -f '/usr/local/nginx/conf/uwsgi_params' \
|| cp conf/uwsgi_params '/usr/local/nginx/conf'
cp conf/uwsgi_params \
'/usr/local/nginx/conf/uwsgi_params.default'
test -f '/usr/local/nginx/conf/scgi_params' \
|| cp conf/scgi_params '/usr/local/nginx/conf'
cp conf/scgi_params \
'/usr/local/nginx/conf/scgi_params.default'
test -f '/usr/local/nginx/conf/nginx.conf' \
|| cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf'
cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf.default'
test -d '/usr/local/nginx/logs' \
|| mkdir -p '/usr/local/nginx/logs'
test -d '/usr/local/nginx/logs' \
|| mkdir -p '/usr/local/nginx/logs'
test -d '/usr/local/nginx/html' \
|| cp -R html '/usr/local/nginx'
test -d '/usr/local/nginx/logs' \
|| mkdir -p '/usr/local/nginx/logs'
make[1]: Leaving directory `/soft/nginx-1.10.2'
[root@LFTp-Svn01 nginx-1.10.2]# echo $?
0
#测试安装没问题
#!/bin/bash
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/run/nginx.pid
RETVAL=0
prog="nginx"
. /etc/rc.d/init.d/functions
. /etc/sysconfig/network
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
start() {
if [ -e $nginx_pid ];then
echo "nginx already running…."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
reload() {
echo -n $"Reloading $prog: "
#kill -HUP \`cat ${nginx\_pid}\`
killproc $nginxd -HUP
RETVAL=$?
echo
}
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
user nobody;
worker_processes 1;
worker_rlimit_nofile 65535;
#error_log logs/error.log;
pid logs/nginx.pid;
events {
worker_connections 65535;
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" "$request\_time"';
#access\_log logs/access.log main;
sendfile on;
tcp\_nopush on;
keepalive\_timeout 65;
client\_max\_body\_size 64M;
gzip on; #开启gzip
gzip\_min\_length 1024;
gzip\_buffers 4 8k;
gzip\_types application/x-javascript text/css application/xml;
fastcgi\_connect\_timeout 300;
fastcgi\_read\_timeout 300;
fastcgi\_send\_timeout 300;
fastcgi\_buffer\_size 64k;
fastcgi\_buffers 4 32k;
fastcgi\_busy\_buffers\_size 64k;
fastcgi\_temp\_file\_write\_size 64k;
#安全检查需要禁止缓存
#expires 0;
expires 1d;
#add\_header Pragma no-cache;
#add\_header Cache-Control no-cache;
#add\_header Cache-Control no-store;
#add\_header Cache-Control must-revalidate;
#安全需要禁止iFrame,防止iFrame嵌入
add\_header X-Frame-Options SAMEORIGIN;
add\_header via $server\_name:$server\_port(php01);
include vhost/\*.conf;
}
nginx.conf
server {
listen 80 ;
server_name nginx.lain.xyz ;
access_log logs/access.nginx.log main;
error_log logs/error.nginx.log;
location ^~ /lain/ {
root /home/www/;
}
location / {
root /home/www/lain/webroot;
index index.php index.html index.htm;
rewrite ^(.\*).do$ $1.php last;
}
location ~ \\.php$ {
fastcgi\_pass unix:/dev/shm/php-fpm.sock;
root /home/www/lain/webroot;
fastcgi\_index index.php;
fastcgi\_param SCRIPT\_FILENAME
/home/www/ehome_pay_op/webroot/$fastcgi_script_name;
include fastcgi_params;
}
location ~ .*\.(gif|jpg|png|htm|html|css|js|flv|ico|swf)(.*) {
root /home/www/lain/webroot;
#expires 30d;
log_not_found off; #禁用not found 报错
}
error_page 403 404 /40x.html;
location = /40x.html {
root html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
nginx.lain.xyz
手机扫一扫
移动阅读更方便
你可能感兴趣的文章