nginx备忘

centos

yum -y install gcc gcc-c++ autoconf.x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64 libxml2-devel.x86_64 zlib-devel.x86_64 glibc-devel.x86_64 glib2-devel.x86_64 bzip2-devel.x86_64 ncurses-devel.x86_64 curl-devel.x86_64 e2fsprogs-devel.x86_64 krb5-devel.x86_64 libidn-devel.x86_64 openssl-devel.x86_64 openldap-devel.x86_64 freetds.x86_64 freetds-devel.x86_64 mysql.x86_64 mysql-devel.x86_64 unixODBC.x86_64 unixODBC-devel.x86_64 libxslt libtool-ltdl-devel.x86_64 compat-libcom_err libtidy-devel.x86_64 libmcrypt-devel.x86_64 mhash-devel.x86_64 ImageMagick-devel.x86_64 ImageMagick.x86_64 readline-devel pcre-devel openssl-devel curl.x86_64 libcurl.x86_64 libcurl-devel.x86_64 gmp-devel.x86_64 gmp.x86_64 libxslt.x86_64 libxslt-devel.x86_64

安装nginx
cd /data/packages
tar xzvf ngx_openresty-1.9.3.1.tar.gz
cd ngx_openresty-1.9.3.1
./configure –with-lua51 –with-debug –prefix=/data/openresty
make
make install
ln -s /data/openresty/nginx   /data/nginx

 

nginx.conf

worker_processes 4;

events {
worker_connections 10240;
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”‘;

access_log /data/logs/nginx/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;
proxy_redirect off;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 15;
proxy_send_timeout 15;
proxy_read_timeout 15;
proxy_buffers 32 4k;

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
include hosts/*.conf;
}

 

nginx/conf/hosts下

web.conf

upstream webServer {
server 123.100.1.2:8888 weight=3 max_fails=2 fail_timeout=10s;
server 123.100.1.3:8888 weight=3 max_fails=2 fail_timeout=10s;
}

server {
listen 80 default;

#server_name webserver.com;  //假如不注释 和下面443的servername冲突

access_log /data/logs/nginx/webServer-access.log main;
error_log /data/logs/nginx/webServer-error.log;

location / {
proxy_pass http://webServer;
}

server {
listen 443;
server_name   webserver.com;
access_log /data/logs/nginx/webServer-access.log main;
error_log /data/logs/nginx/webServer-error.log;
ssl on;
ssl_certificate /etc/nginx/key/hk_com.crt;
ssl_certificate_key /etc/nginx/key/server.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_session_timeout 5m;
ssl_session_cache off;

location / {
proxy_pass http://webServer;;
}
}

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>