Linux 离线安装nginx-1.9.9

3 篇文章 0 订阅
1 篇文章 0 订阅

Linux 安装nginx

环境安装步骤

下载

下载地址:http://nginx.org/download/,下载nginx-1.9.9
在这里插入图片描述

上传服务器解压

将下载的nignx源码包上传到linux服务器上,解压

xx@x-x-x-xx:~$tar xvf nginx-1.9.9.tar.gz 

安装

安装编译工具及库文件

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

app@x-x-x-xx:~$sudo yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
……

Installed:
  gcc-c++.x86_64 0:4.8.5-44.el7                                                                              libtool.x86_64 0:2.4.2-22.el7_3                                                                             

Dependency Installed:
  autoconf.noarch 0:2.69-11.el7   automake.noarch 0:1.13.4-3.el7   libstdc++-devel.x86_64 0:4.8.5-44.el7   m4.x86_64 0:1.4.16-10.el7   perl-Data-Dumper.x86_64 0:2.145-3.el7   perl-Test-Harness.noarch 0:3.28-3.el7  

Updated:
  make.x86_64 1:3.82-24.el7             openssl.x86_64 1:1.0.2k-19.el7             openssl-devel.x86_64 1:1.0.2k-19.el7             zlib.x86_64 0:1.2.7-18.el7             zlib-devel.x86_64 0:1.2.7-18.el7            

Dependency Updated:
  cpp.x86_64 0:4.8.5-44.el7       gcc.x86_64 0:4.8.5-44.el7       libgcc.x86_64 0:4.8.5-44.el7       libgomp.x86_64 0:4.8.5-44.el7       libstdc++.x86_64 0:4.8.5-44.el7       openssl-libs.x86_64 1:1.0.2k-19.el7      

Complete!

配置

进入nginx解压后的根目录,配置

app@x-x-x-xx:~/nginx-1.9.9$./configure --prefix=/home/app/nginx-1.9.9
checking for OS
 + Linux 3.10.0-327.el7.x86_64 x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
……
  nginx path prefix: "/home/app/nginx-1.9.9"
  nginx binary file: "/home/app/nginx-1.9.9/sbin/nginx"
  nginx configuration prefix: "/home/app/nginx-1.9.9/conf"
  nginx configuration file: "/home/app/nginx-1.9.9/conf/nginx.conf"
  nginx pid file: "/home/app/nginx-1.9.9/logs/nginx.pid"
  nginx error log file: "/home/app/nginx-1.9.9/logs/error.log"
  nginx http access log file: "/home/app/nginx-1.9.9/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"
编译安装

make && make install

xx@x-x-x-x:~/nginx-1.9.9$make && make install

这里编译安装碰到一个异常,原因是/home/app/nginx-1.9.9/logs中的logs目录没有,创建logs目录问题解决

make[1]: Entering directory `/home/app/nginx-1.9.9'
sed -e "s|%%PREFIX%%|/home/app/nginx-1.9.9|" \
        -e "s|%%PID_PATH%%|/home/app/nginx-1.9.9/logs/nginx.pid|" \
        -e "s|%%CONF_PATH%%|/home/app/nginx-1.9.9/conf/nginx.conf|" \
        -e "s|%%ERROR_LOG_PATH%%|/home/app/nginx-1.9.9/logs/error.log|" \
        < man/nginx.8 > objs/nginx.8
make[1]: Leaving directory `/home/app/nginx-1.9.9'
make -f objs/Makefile install
make[1]: Entering directory `/home/app/nginx-1.9.9'
test -d '/home/app/nginx-1.9.9' || mkdir -p '/home/app/nginx-1.9.9'
test -d '/home/app/nginx-1.9.9/sbin'                 || mkdir -p '/home/app/nginx-1.9.9/sbin'
test ! -f '/home/app/nginx-1.9.9/sbin/nginx'                 || mv '/home/app/nginx-1.9.9/sbin/nginx'                         '/home/app/nginx-1.9.9/sbin/nginx.old'
cp objs/nginx '/home/app/nginx-1.9.9/sbin/nginx'
test -d '/home/app/nginx-1.9.9/conf'                 || mkdir -p '/home/app/nginx-1.9.9/conf'
cp conf/koi-win '/home/app/nginx-1.9.9/conf'
cp: ‘conf/koi-win’ and ‘/home/app/nginx-1.9.9/conf/koi-win’ are the same file
make[1]: *** [install] Error 1
make[1]: Leaving directory `/home/app/nginx-1.9.9'
make: *** [install] Error 2
检查配置
  • 正确配置
xx@x-x-x-x:cd /home/app/nginx-1.9.9
xx@x-x-x-x: ls
conf  html  logs  sbin
xx@x-x-x-x: cd sbin/
xx@x-x-x-x:~/nginx-1.9.9/sbin$./nginx -t
nginx: the configuration file /home/app/nginx-1.9.9/conf/nginx.conf syntax is ok
nginx: configuration file /home/app/nginx-1.9.9/conf/nginx.conf test is successful
  • 错误配置,该异常和预编码安装异常是同一个,创建logs目录即解决
xx@x-x-x-x:~/nginx-1.9.9/sbin$./nginx -t
nginx: [alert] could not open error log file: open() "/home/app/nginx-1.9.9/logs/error.log" failed (2: No such file or directory)
nginx: the configuration file /home/app/nginx-1.9.9/conf/nginx.conf syntax is ok
2020/11/17 16:35:24 [emerg] 23911#0: open() "/home/app/nginx-1.9.9/logs/nginx.pid" failed (2: No such file or directory)
nginx: configuration file /home/app/nginx-1.9.9/conf/nginx.conf test failed
启动nginx

没有日志输出说明启动成功

xx@x-x-x-x:~/nginx-1.9.9/sbin$pwd
/home/app/nginx-1.9.9/sbin
xx@x-x-x-x:~/nginx-1.9.9/sbin$./nginx
  • 异常
    nginx 默认的端口是80,如果端口被占用了需要在
    /home/app/nginx-1.9.9/conf/ 下修改nginx.conf文件中server 下listen 为自己想要的端口,这里修改为8888
    server {
        listen       8888;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

访问验证

访问 http://xx.x.x.x:8888
在这里插入图片描述

常用命令

重新载入配置文件
xx@x-x-x-x:~/nginx-1.9.9$./sbin/nginx -s reload -c ./conf/nginx.conf 
xx@x-x-x-x:~/nginx-1.9.9$
重启 Nginx
xx@x-x-x-x:~/nginx-1.9.9$./sbin/nginx -s reopen
xx@x-x-x-x:~/nginx-1.9.9$
停止 Nginx
xx@x-x-x-x:~/nginx-1.9.9$./sbin/nginx -s stop
xx@x-x-x-x:~/nginx-1.9.9$
window 版本 nginx 最新版本 一般结合Tomcat 使用 配置信息如下: #运行用户 user www-data; #启动进程,通常设置成和cpu的数量相等 worker_processes 1; #全局错误日志及PID文件 error_log /var/log/nginx/error.log; pid /var/run/nginx.pid; #工作模式及连接数上限 events { use epoll; #epoll是多路复用IO(I/O Multiplexing)中的一种方式,但是仅用于linux2.6以上内核,可以大大提高nginx的性能 worker_connections 1024;#单个后台worker process进程的最大并发链接数 # multi_accept on; } #设定http服务器,利用它的反向代理功能提供负载均衡支持 http { #设定mime类型,类型由mime.type文件定义 include /etc/nginx/mime.types; default_type application/octet-stream; #设定日志格式 access_log /var/log/nginx/access.log; #sendfile 指令指定 nginx 是否调用 sendfile 函数(zero copy 方式)来输出文件,对于普通应用, #必须设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置为 off,以平衡磁盘与网络I/O处理速度,降低系统的uptime. sendfile on; #tcp_nopush on; #连接超时时间 #keepalive_timeout 0; keepalive_timeout 65; tcp_nodelay on; #开启gzip压缩 gzip on; gzip_disable "MSIE [1-6]\.(?!.*SV1)"; #设定请求缓冲 client_header_buffer_size 1k; large_client_header_buffers 4 4k; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; #设定负载均衡的服务器列表 upstream mysvr { #weigth参数表示权值,权值越高被分配到的几率越大 #本机上的Squid开启3128端口 server 192.168.8.1:3128 weight=5; server 192.168.8.2:80 weight=1; server 192.168.8.3:80 weight=6; } server { #侦听80端口 listen 80; #定义使用www.xx.com访问 server_name www.xx.com; #设定本虚拟主机的访问日志 access_log logs/www.xx.com.access.log main; #默认请求 location / { root /root; #定义服务器的默认网站根目录位置 index index.php index.html index.htm; #定义首页索引文件的名称 fastcgi_pass www.xx.com; fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name; include /etc/nginx/fastcgi_params; } # 定义错误提示页面 error_page 500 502 503 504 /50x.html; location = /50x.html { root /root; } #静态文件,nginx自己处理 location ~ ^/(images|javascript|js|css|flash|media|static)/ { root /var/www/virtual/htdocs; #过期30天,静态文件不怎么更新,过期可以设大一点,如果频繁更新,则可以设置得小一点。 expires 30d; } #PHP 脚本请求全部转发到 FastCGI处理. 使用FastCGI默认配置. location ~ \.php$ { root /root; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /home/www/www$fastcgi_script_name; include fastcgi_params; } #设定查看Nginx状态的地址 location /NginxStatus { stub_status on; access_log on; auth_basic "NginxStatus"; auth_basic_user_file conf/htpasswd; } #禁止访问 .htxxx 文件 location ~ /\.ht { deny all; } } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值