木一 发表于 2018-11-12 12:42:42

nginx安装,配置,优化

  1.下载pcre
  #wgethttp://jaist.dl.sourceforge.net/project/pcre/pcre/7.9/pcre-7.9.tar.gz
  
2.安装pcre-7.9.tar.gz



[*]#tar zxvf pcre-7.9.tar.gz
[*]#cd pcre-7.9/
[*]#./configure --user=www --group=www --prefix=/usr/local/nginx--with-pcre=/root/pcre-7.9/ --with-http_stub_status_module   --with-http_realip_module
[*]#make && make install
  PS:安装pcre 以便Nginx支持rewrite
  3.下载nginx
  
#wget http://sysoev.ru/nginx/nginx-0.8.18.tar.gz
  
4.解压

Java 代码

[*]#tar -zxvf nginx-0.8.18.tar.gz
[*]#cd nginx-0.8.18  


[*]#./configure
[*]
[*]  


  


[*]#make
[*]#make install
  

  
#tar -zxvf nginx-0.7.61.tar.gz
  
#cd nginx-0.7.61
  
#./configure --prefix=/usr/local/nginx --with-pcre=/root/pcre-7.9/ --with-http_stub_status_module--with-http_realip_module
  
#make
  
#make install
  

  

  Ps1: 注意上文中的--with-cc-opt='-O2' --with-cpu-opt=opteron 这是编译器优化,目前最常用的是-02而不是3.后面对应CPU的型号,可参照:http://wiki.gentoo.tw/index.php/HOWTO_CFLAG
  2:
  ./configure --prefix=/usr/local/nginx
  
--with-openssl=/usr/include (启用ssl)
  
--with-pcre=/usr/include/pcre/ (启用正规表达式)
  
--with-http_stub_status_module (安装可以查看nginx状态的程序)
  
--with-http_memcached_module (启用memcache缓存)
  
--with-http_rewrite_module (启用支持url重写)
  

  
5.选项
  -c为 Nginx 指定一个配置文件,来代替缺省的。
  -t 不运行,而仅仅测试配置文件。nginx 将检查配置文件的语法的正确性,并尝试打开配置文件中所引用到的文件。
  -v 显示 nginx 的版本。
  -V 显示 nginx 的版本,编译器版本和配置参数。
  mkdir /var/nginxlog
  
生成记录日志目录
  配置完成,启动服务:
  

  
ulimit -SHn 65535
  
/usr/local/nginx/sbin/nginx
  

  添加nginx,mysql,php的启动项到启动文件:
  

  
vi /etc/rc.local
  
/data/mysql/3306/mysql start
  
/usr/local/php/sbin/php-fpm start
  
/usr/local/nginx/sbin/nginx
  

  日志
  # chmod +w /var/nginxlog
  
# chown -R www:www /var/nginxlog
  
# cd
  
主目录
  
# chmod +w /usr/local/idoicancms
  
# chown -R www:www /usr/local/idoicancms
  

  

  
6.中止运行的进程:

Java 代码

[*]#ps aux | egrep '(PID|nginx)'
[*]USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
[*]root      22130.00.0   67842036 ?      Ss   03:01   0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
[*]#kill -15 2213
  

  
#ps aux | egrep '(PID|nginx)'
  
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
  
root      22130.00.0   67842036 ?      Ss   03:01   0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
  
#kill -15 2213
  

  

  平滑改变 nginx 配置的选项(请注意,在重载前,要先测试一下配置文件):

Java 代码

[*]#nginx -t -c /etc/nginx/nginx.conf
[*]2006/09/16 13:07:10 15686#0: the configuration file /etc/nginx/nginx.conf syntax is ok
[*]2006/09/16 13:07:10 15686#0: the configuration file /etc/nginx/nginx.conf was tested successfully
[*]#ps aux | egrep '(PID|nginx)'
[*]USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
[*]root      22130.00.0   67842036 ?      Ss   03:01   0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
[*]#kill -HUP 2213
  

  
#nginx -t -c /etc/nginx/nginx.conf
  
2006/09/16 13:07:10 15686#0: the configuration file /etc/nginx/nginx.conf syntax is ok
  
2006/09/16 13:07:10 15686#0: the configuration file /etc/nginx/nginx.conf was tested successfully
  
#ps aux | egrep '(PID|nginx)'
  
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
  
root      22130.00.0   67842036 ?      Ss   03:01   0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
  
#kill -HUP 2213
  

  


Nginx状态查看  


  无需重启服务器。
  在虚拟主机(假设为www.example.com)的配置文件中加上:

C代码

[*]location /nginxStatus {
[*]    stub_status      on;
[*]    access_log         on;
[*]    auth_basic         "Nginx Status";
[*]    auth_basic_user_file conf/htpasswd;
[*]}
  

  
location /nginxStatus {
  
stub_status      on;
  
access_log         on;
  
auth_basic         "Nginx Status";
  
auth_basic_user_file conf/htpasswd;
  
}
  

  则直接可以通过访问 www.example.com/nginxStatus查看信息
  但是需要注意,在这里我们打开了安全验证。

C代码

[*]auth_basic         "Nginx Status"; #密码验证的提示语
[*]auth_basic_user_file conf/htpasswd;#用户名和密码存放的文件
  

  
auth_basic         "Nginx Status"; #密码验证的提示语
  
auth_basic_user_file conf/htpasswd;#用户名和密码存放的文件
  

  关于那个文件的生成,请参见工具htpasswd的使用。
  文件中的数据格式是:
  user:cryt-password
  #用户名称:加密后的密码
  这里给大家提供一些在线加密的网站:
  http://www.htaccesstools.com/htpasswd-generator/
  http://home.flash.net/cgi-bin/pw.pl
  在配置完毕后,让我们重载配置文件:


页: [1]
查看完整版本: nginx安装,配置,优化