nginx单机

系统版本:cs7.5

网络环境:阿里云服务器

nginx版本:nginx/1.6.2

一、下载编译工具及库文件 (download是下载到本地;localinstall * 系统会自动根据需要匹配依赖包)

1 yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel --downloadonly --downloaddir=/root/nginx/
2 yum localinstall *

二、安装PCRE

1、下载安装包

1 cd /usr/local/src/
2 wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz

2、解压,进入安装目录

1 tar zxvf pcre-8.35.tar.gz
2 cd pcre-8.35

3、编译安装

1 ./configure
2 make && make install

4、查看版本,验证是否安装成功(8.35)

1 pcre-config --version

三、安装nginx

1、下载安装包

1 cd /usr/local/src/
2 wget http://nginx.org/download/nginx-1.6.2.tar.gz

2、解压,进入安装目录

1 tar zxvf nginx-1.6.2.tar.gz
2 cd nginx-1.6.2

3、编译安装

1  ./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35
2 make && make install

4、查看版本,验证是否安装成功(nginx version: nginx/1.6.2)

1 /usr/local/webserver/nginx/sbin/nginx -v

四、配置nginx

1、创建nginx用户

1 /usr/sbin/groupadd www 
2 /usr/sbin/useradd -g www www

2、nginx配置

 1 user www www;
 2 worker_processes 2; 
 3 error_log /usr/local/webserver/nginx/logs/nginx_error.log crit; #日志位置和日志级别
 4 pid /usr/local/webserver/nginx/nginx.pid;
 5 #Specifies the value for maximum file descriptors that can be opened by this process.
 6 worker_rlimit_nofile 65535;
 7 events
 8 {
 9   use epoll;
10   worker_connections 65535;
11 }
12 http
13 {
14   include mime.types;
15   default_type application/octet-stream;
16   log_format main  '$remote_addr - $remote_user [$time_local] "$request" '
17                '$status $body_bytes_sent "$http_referer" '
18                '"$http_user_agent" $http_x_forwarded_for';
19   
20 #charset gb2312;
21      
22   server_names_hash_bucket_size 128;
23   client_header_buffer_size 32k;
24   large_client_header_buffers 4 32k;
25   client_max_body_size 8m;
26      
27   sendfile on;
28   tcp_nopush on;
29   keepalive_timeout 60;
30   tcp_nodelay on;
31   fastcgi_connect_timeout 300;
32   fastcgi_send_timeout 300;
33   fastcgi_read_timeout 300;
34   fastcgi_buffer_size 64k;
35   fastcgi_buffers 4 64k;
36   fastcgi_busy_buffers_size 128k;
37   fastcgi_temp_file_write_size 128k;
38   gzip on; 
39   gzip_min_length 1k;
40   gzip_buffers 4 16k;
41   gzip_http_version 1.0;
42   gzip_comp_level 2;
43   gzip_types text/plain application/x-javascript text/css application/xml;
44   gzip_vary on;
45  
46   #limit_zone crawler $binary_remote_addr 10m;
47  #下面是server虚拟主机的配置
48  server
49   {
50     listen 80;#监听端口
51     server_name localhost;#域名
52     index index.html index.htm index.php;
53     root /usr/local/webserver/nginx/html;#站点目录
54       location ~ .*\.(php|php5)?$
55     {
56       #fastcgi_pass unix:/tmp/php-cgi.sock;
57       fastcgi_pass 127.0.0.1:9000;
58       fastcgi_index index.php;
59       include fastcgi.conf;
60     }
61     location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$
62     {
63       expires 30d;
64   # access_log off;
65     }
66     location ~ .*\.(js|css)?$
67     {
68       expires 15d;
69    # access_log off;
70     }
71     access_log off;
72   }
73 
74 }

3、检验nginx.conf的正确性

1 /usr/local/webserver/nginx/sbin/nginx -t

     nginx: the configuration file /usr/local/webserver/nginx/conf/nginx.conf syntax is ok
     nginx: configuration file /usr/local/webserver/nginx/conf/nginx.conf test is successful

4、启动nginx

1 /usr/local/webserver/nginx/sbin/nginx

5、web访问IP

 

 nginx常用命令:

1 /usr/local/webserver/nginx/sbin/nginx -s reload            # 重新载入配置文件
2 /usr/local/webserver/nginx/sbin/nginx -s reopen            # 重启 Nginx
3 /usr/local/webserver/nginx/sbin/nginx -s stop              # 停止 Nginx

 

posted on 2019-04-02 11:52  明.Sir  阅读(166)  评论(0编辑  收藏  举报

导航