Nginx环境搭建

Nginx安装

系统平台, centos6.5及以上版本

一、安装编译工具及库文件

yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel

 

二、安装PCRE

PCRE作用是让Nginx支持Rewrite功能

wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz

也可以将tar包下载到本地,然后执行rz命令上传至/usr/local 目录

解压安装包:

 

进入安装目录,编译安装

 

 

编译安装完成,执行 pcre-config --version,如果显示版本信息,则安装完成

 

三、安装Nginx

下载安装包

wget http://nginx.org/download/nginx-1.6.2.tar.gz 

也可以将tar包下载到本地,然后rz/usr/local 目录

创建安装目录, mkdir -p /usr/local/webserver

 

make && make install

安装完成

 

四、Nginx配置

user nobody;
worker_processes 4;
error_log /usr/local/webserver/nginx/logs/nginx_error.log crit;
pid /usr/local/webserver/nginx/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events
{
  use epoll;
  worker_connections 65535;
}
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';
  
#charset gb2312;
     
  server_names_hash_bucket_size 128;
  client_header_buffer_size 32k;
  large_client_header_buffers 4 32k;
  client_max_body_size 8m;
     
  sendfile on;
  tcp_nopush on;
  keepalive_timeout 60;
  tcp_nodelay on;
  fastcgi_connect_timeout 300;
  fastcgi_send_timeout 300;
  fastcgi_read_timeout 300;
  fastcgi_buffer_size 64k;
  fastcgi_buffers 4 64k;
  fastcgi_busy_buffers_size 128k;
  fastcgi_temp_file_write_size 128k;
  gzip on; 
  gzip_min_length 1k;
  gzip_buffers 4 16k;
  gzip_http_version 1.0;
  gzip_comp_level 2;
  gzip_types text/plain application/x-javascript text/css application/xml;
  gzip_vary on;
 
  #limit_zone crawler $binary_remote_addr 10m;
 upstream nginx_name {
    server localhost:8082 weight=1;
}
 server
  {
    listen 80;
    server_name localhost;
    rewrite ^(.*) https://$host$1 permanent;
  }
  server
  {
listen 443;
server_name nginx_name;
ssl on;
ssl_certificate 1_aaa.crt;
ssl_certificate_key 2_bbb.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
location / {
        proxy_pass http://localhost:8080/project_name/;
    }
    location /project_name/ {
        proxy_pass http://localhost:8082/project_name/;
        proxy_redirect off;
   proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    location /project_name/ {
proxy_pass http://localhost:8083/project_name/;
    }
    location /pic/original/ {
        root /opt/;
        autoindex on;
    }
    location /project_name/ {
    proxy_pass http://localhost:8080/project_name/;
    }
  }
}

五、启动Nginx

/usr/local/webserver/nginx/sbin/nginx -s reload   #重新载入配置文件

/usr/local/webserver/nginx/sbin/nginx -s reopen    #重启Nginx

/usr/local/webserver/nginx/sbin/nginx -s stop    #停止Nginx

阅读更多
个人分类: nginx
想对作者说点什么? 我来说一句

Ubuntu下apt-get方式安装LNMP

2012年10月09日 18KB 下载

nginx结合tomcat实现负载分担入门

2014年06月05日 342KB 下载

Nginx环境打架

2016年11月24日 551KB 下载

没有更多推荐了,返回首页

不良信息举报

Nginx环境搭建

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭