安装Nginx

南楼画角 提交于 2020-03-24 15:29:29
 1. 安装编译工具及库文件 

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

 2. 安装 PCRE 
下载pcre:
[root@bogon src]# cd /usr/local/src/
[root@bogon src]# wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz解压安装包:
[root@bogon src]# tar zxvf pcre-8.35.tar.gz
进入安装包目录:
[root@bogon src]# cd pcre-8.35编译安装 :
[root@bogon pcre-8.35]# ./configure
[root@bogon pcre-8.35]# make && make install查看pcre版本:
[root@bogon pcre-8.35]# pcre-config --version
3. 安装 nginx
下载nginx:
[root@bogon src]# cd /usr/local/src/
[root@bogon src]# wget http://nginx.org/download/nginx-1.6.2.tar.gz
解压:
[root@bogon src]# tar zxvf nginx-1.6.2.tar.gz
进入目录:
[root@bogon src]# cd nginx-1.6.2
编译安装:
[root@bogon nginx-1.6.2]# ./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35
[root@bogon nginx-1.6.2]# make
[root@bogon nginx-1.6.2]# make install
查看nginx版本:
[root@bogon nginx-1.6.2]# /usr/local/webserver/nginx/sbin/nginx -v
4. 配置 nginx
创建 Nginx 运行使用的用户:
[root@bogon conf]# /usr/sbin/groupadd www 
[root@bogon conf]# /usr/sbin/useradd -g www www配置nginx.conf:/usr/local/webserver/nginx/conf/nginx.conf
 1 user www www;
 2 worker_processes 2; #设置值和CPU核心数一致
 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    include  vhost/*.conf; #包含多个文件 用于区分
74 }

 

配置nginx.conf:
[root@bogon conf]# /usr/local/webserver/nginx/sbin/nginx -t
Nginx 启动:
[root@bogon conf]# /usr/local/webserver/nginx/sbin/nginx
ps.  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
 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!