一、一键安装四个依赖

yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel

二、创建一个安装目录,并下载nginx安装包
cd /usr/local
mkdir nginx   #创建目录名为nginx的文件夹
cd nginx
wget http://nginx.org/download/nginx-1.13.7.tar.gz #下载nginx安装包

三、安装nginx
cd /usr/local/nginx  #进入nginx目录
tar zxvf nginx-1.13.7.tar.gz  -C  /usr/local/nginx #解压
cd /usr/local/nginx/nginx-1.13.7
./configure --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/nginx.conf   #执行命令
如果执行下面的命令时报: -bash: ./configure: Permission denied 错误,则执行:
bash ./configure --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/nginx.conf
如果执行下面的命令时报: 找不到logs文件夹 错误,则在安装目录中创建 logs文件夹
make #执行make命令
make install #执行make install命令

四、检查及启动nginx
/usr/local/nginx/sbin/nginx -t  #检查一下修改过的配置文件是否正确

cd /usr/local/nginx/sbin  #进入安装目录

./nginx  #启动nginx

如果启动没有报错,则启动成功。在浏览中输入服务器ip,如果能访问到nginx首页,则安装成功。有时可能还要关闭防火墙才能访问。

五、如果修改配置文件后要重启nginx服务

/usr/local/nginx/sbin/nginx -s reload  #重启nginx

附:nginx 优化后的配置文件


#user  nobody;
worker_processes 1; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections 102400;#number的值不能大于操作系统能打开的最大的文件句柄数
accept_mutex on;#优化同一时刻只有一个请求而避免多个睡眠进程被唤醒的设置,on为防止被同时唤醒,默认为off
multi_accept on; #打开同时接受多个新网络连接请求的功能
use epoll; #使用epoll事件驱动,因为epoll的性能相比其他事件驱动要好很多
} http {
server_tokens off; #隐藏ngxin版本号
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"'; #access_log logs/access.log main; sendfile on;
#tcp_nopush on; #keepalive_timeout 0;
keepalive_timeout 65; gzip on;
#gzip_static on;
gzip_disable "msie6"; #不使用gzip IE6
gzip_min_length 10k; #gzip压缩最小文件大小,超出进行压缩(自行调节)
gzip_buffers 4 16k; #buffer 不用修改
gzip_comp_level 3; #压缩级别:1-10,数字越大压缩的越好,时间也越长
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; #压缩文件类型
gzip_vary off; #跟Squid等缓存服务有关,on的话会在Header里增加 "Vary: Accept-Encoding" server { listen 80;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / {
add_header Cache-Control "no-cache, no-store";
root /data/xyweb/;#
index index.html index.htm;
expires -1;
} #error_page 404 /404.html; # redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
} server {
listen 8089;#
server_name localhost; location / {
root /data/xyweb/machine;
index index.html index.htm;
} error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
} server {
listen 8088;#
server_name localhost; location / {
root /data/xyweb/rzweb;
index index.html index.htm;
} error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
} server {
listen 8086;#
server_name localhost; location / {
root /data/xyFiles;
index index.html index.htm;
} error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
} server {
listen 80;#
server_name pay.xynetweb.com;
location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://195.6.71.888:8090/service-pay/pay/;
}
} server {
listen 80;#
server_name paytest.xynetweb.com;
location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://195.6.4.448:6017/service-pay/pay/;
} location /api/pay/jft/ {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://195.6.4.448:6017/service-pay-wx/pay/api/jft/;
}
} # another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias; # location / {
# root html;
# index index.html index.htm;
# }
#} # HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost; # ssl_certificate cert.pem;
# ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on; # location / {
# root html;
# index index.html index.htm;
# }
#} }

 

linux 下nginx安装的更多相关文章

  1. VMware Linux 下 Nginx 安装配置 - nginx.conf 配置 [负载两个 Tomcat] (三)

    首先启动Nginx 1. 相关浏览 两个 Tomcat 配置:  VMware Linux 下 Nginx 安装配置 - Tomcat 配置 (二) Nginx 安装配置启动: VMware Linu ...

  2. VMware Linux 下 Nginx 安装配置 - Tomcat 配置 (二)

    准备工作 相关浏览: VMware Linux 下 Nginx 安装配置 (一) 1. 选在 /usr/local/ 下创建 softs 文件夹,通过 ftp 命令 把 apache-tomcat-7 ...

  3. Linux下Nginx安装/启动/重启/停止

    Nginx是高性能的web服务器也是非常好用反向代理服务器,可以实现负载均衡,动静分离等策略,在linux下用的非常多.下面是下载地址   http://nginx.org/en/download.h ...

  4. linux下nginx安装、配置实战

    1什么是Nginx Nginx("enginex")是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器,在高连接并发的情况下Nginx是Apac ...

  5. linux下Nginx 安装配置

    Nginx 安装 一.首先要安装 PCRE PCRE 作用是让 Ngnix 支持 Rewrite 功能. 1.下载 PCRE 安装包,下载地址: http://downloads.sourceforg ...

  6. Linux下Nginx安装

    前提: 1.需要gcc环境:yum install gcc-c++ 2.需要第三方开发包: PCRE.zlib.openssl yum install -y pcre pcre-devel yum i ...

  7. VMware Linux 下 Nginx 安装配置 (一)

    资源准备 1. pcre-8.34.tar.gz: ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ 2. zlib-1.2.8.tar.g ...

  8. linux下nginx安装php

    把php安装包上传到linux的/usr/local/src 1.解压 cd /usr/local/src tar zxvf php-5.6.9.tar.gz cd php-5.6.9 2.编译安装 ...

  9. Linux下nginx安装与配置

    部分Linux发布版的默认安装已经集成了nginx,查看方法ls /usr/local,若已有nginx文件夹说明已集成. nginx依赖库pcre与zlib,且pcre依赖于gcc与gcc-c++, ...

  10. linux下Nginx安装Zend Optimizer组件步骤

    注意:Zend Optimizer 在php5.3以上的版本已经集成了,所以php5.3以上的版本没必要安装了.而推出了Zend Guard Loader. http://www.zend.com/e ...

随机推荐

  1. [转]天才计算机程序员 -- fabrice bellard

    这位老兄就是用javascript写linux的那位,他的主页是:http://bellard.org/ 上面有他的几个作品,包括qemu,ffmpeg,tcc等. 这个世界从来不缺天才,只缺乏利用天 ...

  2. 【leetcode 简单】 第七十五题 第一个错误的版本

    你是产品经理,目前正在带领一个团队开发新的产品.不幸的是,你的产品的最新版本没有通过质量检测.由于每个版本都是基于之前的版本开发的,所以错误的版本之后的所有版本都是错的. 假设你有 n 个版本 [1, ...

  3. Android手动回收bitmap,引发Canvas: trying to use a recycled bitmap处理

    在做Android的开发的时候,在ListView 或是 GridView中需要加载大量的图片,为了避免加载过多的图片引起OutOfMemory错误,设置了一个图片缓存列表 Map<String ...

  4. 关于注入抽象类报could not autowire field的问题

    昨天工作中遇到了一个很奇葩的问题,之前一直都没考虑过抽象类这块,一直用的注入接口实现类: 先看下错误: 因为在类中注入了一个抽象类,之前只有一个继承子类,所以没问题,这里要说一下抽象类的实例化: 抽象 ...

  5. SQL SERVER2008 镜像全攻略

    --在非域控环境中创建数据库镜像, 我们必须使用证书来创建数据库镜像. 大致的步骤包括: --在为数据库镜像配置的每个服务器实例上执行下列步骤: --在 master 数据库中,创建数据库主密钥. - ...

  6. GreenPlum学习笔记:新手入门命令

    1.命令行登录数据库 psql -h 192.168.111.111 -U username -d dbname 其中,username为数据库用户名,dbname为数据库名,执行后提示输入密码.(可 ...

  7. 全方位掌握nsis脚本

    NSIS 确实是一个不错的安装程序制作软件.新版本 2.0a7 真正实现了中文支持和支持 WinXP 的安装对话框. 不过要用它实现漂亮的安装界面和完美的安装功能就必须好好的写脚本. 而 NSIS 的 ...

  8. Docker镜像和容器

    本节内容: 安装Docker 卸载docker 镜像基本操作 容器基本操作 一.安装Docker Docker 对 Linux 内核版本的最低要求是3.10,如果内核版本低于 3.10 会缺少一些运行 ...

  9. 一步一步学习IdentityServer3 (10)

    在某些服务器环境下 identityserver3 会闹情绪, 比如在google浏览器下授权失败(陷入死循环) 查了很多资料好像然并卵 Microsoft.Owin.Security.Notific ...

  10. python实现获取系统版本和mac信息上传到指定接口

    import os,platform,uuid,urllib.parse,urllib.request,json def BeforeSystemRequests(): ''' the systemi ...