Nginx 安装配置入门

来源:互联网 发布:阿贝成像原理实验数据 编辑:程序博客网 时间:2024/05/16 02:33

http://www.runoob.com/linux/nginx-install-setup.html

http://nginx.org/en/download.html

http://tengine.taobao.org/book/

Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器

反向代理(Reverse Proxy)方式是指以代理服务器来接受internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给internet上请求连接的客户端,此时代理服务器对外就表现为一个服务器。  
入门教程
http://cxshun.iteye.com/blog/1535188
http://www.runoob.com/linux/nginx-install-setup.html

源码安装:

准备:sudo apt-get install libpcre3 libpcre3-dev libssl-dev openssl zlib1g-dev在源码安装的时候,需要安装编译环境sudo apt-get install libtoolsudo apt-get install gcc-c++sudo apt-get install build-essentialsudo apt-get updatesudo apt-get upgradesudo apt-get install gcc-c++开始安装pcrewget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gztar zxvf pcre-8.35.tar.gzcd pcre-8.35./configuresudo make && sudo make install或者直接安装pcresudo apt-get install -y libpcre3 libpcre3-dev zlib1g-devpcre-config --version安装nginxwget http://nginx.org/download/nginx-1.6.2.tar.gztar zxvf nginx-1.6.2.tar.gzcd nginx-1.6.2./configuresudo make && sudo make install/usr/local/nginx/sbin/nginx -v创建 Nginx 运行使用的用户:www密码:www:groupadd www useradd -g www www备份cd  /usr/local/nginx/conf/cp nginx.conf nginx_old.conf配置nginx.conf ,将/usr/local/nginx/conf/nginx.conf替换为以下内容gedit /usr/local/nginx/conf/nginx.conf测试配置是否成功/usr/local/nginx/sbin/nginx -t启动nginxsudo /usr/local/nginx/sbin/nginx浏览器打开http://127.0.0.1:8888/Nginx 其他命令/usr/local/nginx/sbin/nginx -s reload            # 重新载入配置文件/usr/local/nginx/sbin/nginx -s reopen            # 重启 Nginx/usr/local/nginx/sbin/nginx -s stop              # 停止 Nginx

配置例子:

user www www;worker_processes 4; #设置值和CPU核心数一致error_log /usr/local/nginx/logs/nginx_error.log crit; #日志位置和日志级别pid /usr/local/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 es.com {        server 127.0.0.1:9200;     }     server {          listen 9999;          server_name localhost:9200;          location / {              proxy_pass http://es.com;              proxy_set_header  X-Real-IP  $remote_addr;              proxy_set_header Host $host;          }     } #端口转发 http://my.oschina.net/kear/blog/109868upstream 131.com {        server 192.168.1.131:9200;     }     server {          listen 7777;           location / {              proxy_pass http://131.com;              proxy_set_header  X-Real-IP  $remote_addr;              proxy_set_header Host $host;          }     }  #下面是server虚拟主机的配置 server  {    listen 8888;#监听端口    server_name localhost;#域名    index index.html index.htm index.php;    root /usr/local/nginx/html;#站点目录location ~ .*\.(php|php5)?$    {      #fastcgi_pass unix:/tmp/php-cgi.sock;      fastcgi_pass 127.0.0.1:9000;      fastcgi_index index.php;      include fastcgi.conf;    }    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$    {      expires 30d;  # access_log off;    }    location ~ .*\.(js|css)?$    {      expires 15d;   # access_log off;    }    access_log on;  }}


IP端口转发 代理配置:

    upstream es.com {        server 127.0.0.1:9200;     }     server {          listen 9999;          server_name localhost:9200;          location / {              proxy_pass http://es.com;              proxy_set_header  X-Real-IP  $remote_addr;              proxy_set_header Host $host;          }     } #端口转发 http://my.oschina.net/kear/blog/109868upstream 131.com {        server 192.168.1.131:9200;     }     server {          listen 7777;           location / {              proxy_pass http://131.com;              proxy_set_header  X-Real-IP  $remote_addr;              proxy_set_header Host $host;          }     } 

0 0
原创粉丝点击