nginx 安装

来源:互联网 发布:天津日报大厦知乎 编辑:程序博客网 时间:2024/06/05 18:03

1:安装openssl

 tar zxvf openssl-1.0.0a.tar.gz

cd openssl-1.0.0a

[migu_rs@LS-NGINX03-102-48openssl-1.0.0a]$./config --prefix=/opt/aspire/product/migu_rs/ssl

[migu_rs@LS-NGINX03-102-48 openssl-1.0.0a]$ make

[migu_rs @LS-NGINX03-102-48 openssl-1.0.0a]# make install

 

2:安装pcre

Tar zxvf  pcre-8.37.tar.gz

[migu_rs@LS-NGINX03-102-48 ~]$ cd pcre-8.37

[migu_rs@LS-NGINX03-102-48pcre-8.37]$./configure --prefix=/opt/aspire/product/migu_rs/pcre

[migu_rs@LS-NGINX03-102-48 pcre-8.37]$ make

[migu_rs @LS-NGINX03-102-48 pcre-8.37]# make install

 

3: 安装zlib

Tar zxvf  zlib-1.2.7.tar.gz

[migu_rs@LS-NGINX03-102-48 zlib-1.2.7]$ ./configure --prefix=/opt/aspire/product/migu_rs/zlib

[migu_rs@LS-NGINX03-102-48 zlib-1.2.7]$make

[migu_rs@LS-NGINX03-102-48 zlib-1.2.7]$ make install

 

4:nginx 安装

安装包:nginx-1.8.0.tar.gz

进到安装包所在路径

解压$ tar zxvf nginx-1.8.0.tar.gz

 

5:nginx编译及安装

安装路径需修改成你要安装的路径

$ cd ../../../   (回到解压出来的文件夹的根目录)

$./configure --prefix=/opt/aspire/product/migu_rs/nginx

--conf-path=/opt/aspire/product/migu_rs/nginx/conf/nginx.conf 

--with-http_ssl_module  --with-http_flv_module  --with-http_gzip_static_module 

--with-pcre=../pcre-8.37 --with-openssl=../openssl-1.0.0a

--prefix 路径以实际情况为准

 

6 :nginx配置修改

6.1:查看逻辑CPU个数,配置worker_processes

cat /proc/cpuinfo| grep "processor"| wc -l

配置worker_processes: 

worker_processes  4;

worker_cpu_affinity 0001 0010 0100 1000;

6.2:全局错误日志类型

error_log  logs/error.log;  将前面的#去除,使用这个

6.3:进程文件

pid  logs/nginx.pid; 将前面的#去除

 

6.4:worker_rlimit_nofile设置

配置一个nginx进程打开的最多文件描述符数目,但是nginx分配请求并不均匀 ,所以配置和ulimit -n查询结果一样

worker_rlimit_nofile 1024;

 

6.5:参考事件模型use [ kqueue | rtsig | epoll | /dev/poll | select | poll ];

events {

    use epoll;

    worker_connections  1024;

}

6.6:设定http服务器 除#

 

   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  logs/access.log  main;

  #access_log  logs/access.log  main;  去除# 并重命名

6.7:gzip模块设置

 

gzip on; #开启gzip压缩输出

 

 

6.8:修改listen端口为9091,去除#error_page  404,

    server {

        listen       9091;

        server_name  localhost;

 

error_page  404              /404.html; 

 

6.9:修改初始页面信息删除nginx信息

/opt/aspire/product/migu_rs/nginx/html/index.html

修改为:

<!DOCTYPE html>

<html>

<head>

<title>Welcome to migu_server</title>

<style>

    body {

        width: 35em;

        margin: 0 auto;

        font-family: Tahoma, Verdana, Arial, sans-serif;

    }

</style>

</head>

<body>

<h1>migu_server!</h1>

<p>this is for migu_rs web server  </p>

 

</body>

</html>

 

6:安装后检查验证

编译检查

[migu_rs@LS-NGINX03-102-48 sbin]$ pwd

/opt/aspire/product/migu_rs/nginx/sbin

[migu_rs@LS-NGINX03-102-48 sbin]$ ./nginx  -t

nginx: the configuration file /opt/aspire/product/migu_rs/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /opt/aspire/product/migu_rs/nginx/conf/nginx.conf test is successful

显示ok和succsessfui代表安装成功

 

进程端口url检查

migu_rs@LS-NGINX03-102-48 sbin]$ ps -ef | grep nginx

migu_rs  14653     1  0 10:04 ?        00:00:00 nginx: master process ./nginx

migu_rs  14654 14653  0 10:04 ?        00:00:00 nginx: worker process

migu_rs  14655 14653  0 10:04 ?        00:00:00 nginx: worker process

migu_rs  14656 14653  0 10:04 ?        00:00:00 nginx: worker process

migu_rs  14657 14653  0 10:04 ?        00:00:00 nginx: worker process

migu_rs  15810 15703  0 11:14 pts/0    00:00:00 grep nginx

[migu_rs@LS-NGINX03-102-48 sbin]$

[migu_rs@LS-NGINX03-102-48 sbin]$

[migu_rs@LS-NGINX03-102-48 sbin]$ netstat -an | grep 9091

tcp        0      0 0.0.0.0:9091                0.0.0.0:*                   LISTEN     

[migu_rs@LS-NGINX03-102-48 sbin]$

Web 也没验证检查

http://172.18.102.46:9091 看是否正常

原创粉丝点击