nginx安装图解_动力节点Java学院整理

 更新时间:2017年08月24日 11:27:58   作者:runoob  
这篇文章主要为大家详细介绍了nginx安装的图文教程,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

Nginx 安装

系统平台:CentOS release 6.6 (Final) 64位。

一、安装编译工具及库文件

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

二、首先要安装 PCRE

PCRE 作用是让 Ngnix 支持 Rewrite 功能。

1、下载 PCRE 安装包,下载地址:http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz

[root@bogon src]# wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz

2、解压安装包:

[root@bogon src]# tar zxvf pcre-8.35.tar.gz

3、进入安装包目录

[root@bogon src]# cd pcre-8.35

4、编译安装

[root@bogon pcre-8.35]# ./configure
[root@bogon pcre-8.35]# make && make install

5、查看pcre版本

[root@bogon pcre-8.35]# pcre-config --version

安装 Nginx

1、下载 Nginx,下载地址:http://nginx.org/download/nginx-1.6.2.tar.gz

[root@bogon src]# wget http://nginx.org/download/nginx-1.6.2.tar.gz

2、解压安装包

[root@bogon src]# tar zxvf nginx-1.6.2.tar.gz

3、进入安装包目录

[root@bogon src]# cd nginx-1.6.2

4、编译安装

[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

5、查看nginx版本

[root@bogon nginx-1.6.2]# /usr/local/webserver/nginx/sbin/nginx -v

到此,nginx安装完成。

Nginx 配置

创建 Nginx 运行使用的用户 www:

[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替换为以下内容

注意下面的配置请酌情添加,不要全部照抄完。新手很容易报错

[root@bogon conf]# cat /usr/local/webserver/nginx/conf/nginx.conf

user www www;
worker_processes 2; #设置值和CPU核心数一致
error_log /usr/local/webserver/nginx/logs/nginx_error.log crit; #日志位置和日志级别
pid /usr/local/webserver/nginx/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events
{
 use epoll;
 worker_connections 65535;
}
http
{
 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';
 
#charset gb2312;
  
 server_names_hash_bucket_size 128;
 client_header_buffer_size 32k;
 large_client_header_buffers 4 32k;
 client_max_body_size 8m;
  
 sendfile on;
 tcp_nopush on;
 keepalive_timeout 60;
 tcp_nodelay on;
 fastcgi_connect_timeout 300;
 fastcgi_send_timeout 300;
 fastcgi_read_timeout 300;
 fastcgi_buffer_size 64k;
 fastcgi_buffers 4 64k;
 fastcgi_busy_buffers_size 128k;
 fastcgi_temp_file_write_size 128k;
 gzip on; 
 gzip_min_length 1k;
 gzip_buffers 4 16k;
 gzip_http_version 1.0;
 gzip_comp_level 2;
 gzip_types text/plain application/x-javascript text/css application/xml;
 gzip_vary on;
 
 #limit_zone crawler $binary_remote_addr 10m;
 #下面是server虚拟主机的配置
 server
 {
 listen 80;#监听端口
 server_name localhost;#域名
 index index.html index.htm index.php;
 root /usr/local/webserver/nginx/html;#站点目录
  location ~ .*\.(php|php5)?$
 {
  #fastcgi_pass unix:/tmp/php-cgi.sock;
  fastcgi_pass 127.0.0.1:9000;
  fastcgi_index index.php;
  include fastcgi.conf;
 }
 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$
 {
  expires 30d;
 # access_log off;
 }
 location ~ .*\.(js|css)?$
 {
  expires 15d;
 # access_log off;
 }
 access_log off;
 }

}

检查配置文件ngnix.conf的正确性命令:

[root@bogon conf]# /usr/local/webserver/nginx/sbin/nginx -t

启动 Nginx

Nginx 启动命令如下:

[root@bogon conf]# /usr/local/webserver/nginx/sbin/nginx

访问站点

从浏览器访问我们配置的站点ip:

Nginx 其他命令

以下包含了 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

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

相关文章

  • nginx代理转发报错405 Method Not Allowed解决

    nginx代理转发报错405 Method Not Allowed解决

    这篇文章主要为大家介绍了解决nginx代理转发报错405 Method Not Allowed解决方法详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-08-08
  • nginx配置反向代理到gin的方法步骤

    nginx配置反向代理到gin的方法步骤

    本文使用Nginx进行反向代理到Gin应用的配置步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2024-11-11
  • nginx快速部署一个网站服务(多域名+多端口)

    nginx快速部署一个网站服务(多域名+多端口)

    本文主要介绍了nginx快速部署一个网站服务,并实现多域名和多端口,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2023-10-10
  • nginx中的proxy_redirect的使用案例详解

    nginx中的proxy_redirect的使用案例详解

    proxy_redirect 该指令用来修改被代理服务器返回的响应头中的Location头域和“refresh”头域,这篇文章主要介绍了nginx中的proxy_redirect的使用案例详解,需要的朋友可以参考下
    2024-06-06
  • 通过Nginx+Tomcat+Redis实现持久会话

    通过Nginx+Tomcat+Redis实现持久会话

    这篇文章主要介绍了通过Nginx+Tomcat+Redis实现持久会话的相关资料,非常不错,具有参考借鉴价值,需要的朋友可以参考下
    2017-11-11
  • nginx如何配置同一个端口转发多个项目

    nginx如何配置同一个端口转发多个项目

    这篇文章主要介绍了nginx如何配置同一个端口转发多个项目问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2024-01-01
  • 使用Bash脚本和Logrotate实现Nginx日志切割的方法

    使用Bash脚本和Logrotate实现Nginx日志切割的方法

    Logrotate是一个Linux系统上用来管理日志文件的工具,它可以定期轮转日志文件、压缩旧的日志文件以及删除过期的日志文件,这篇文章主要介绍了使用Bash脚本和Logrotate实现Nginx日志切割,需要的朋友可以参考下
    2024-05-05
  • 详解nginx实现ssl反向代理实战

    详解nginx实现ssl反向代理实战

    本篇文章主要介绍了nginx实现ssl反向代理实战,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-01-01
  • win10安装配置nginx的过程

    win10安装配置nginx的过程

    这篇文章主要介绍了win10安装配置nginx的过程,帮助大家更好的理解和使用nginx服务器,感兴趣的朋友可以了解下
    2020-10-10
  • 详解NGINX访问https跳转到http的解决方法

    详解NGINX访问https跳转到http的解决方法

    这篇文章主要介绍了详解NGINX访问https跳转到http的解决方法,非常具有实用价值,需要的朋友可以参考下
    2017-06-06

最新评论