设为首页 收藏本站
查看: 1044|回复: 0

[经验分享] nginx安装,配置,优化

[复制链接]

尚未签到

发表于 2018-11-12 12:42:42 | 显示全部楼层 |阅读模式
  1.下载pcre
  #wget  http://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
  

  

  Ps  1: 注意上文中的--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
  

  日志
  [root@lv183 nginxlog]# chmod +w /var/nginxlog
  
[root@lv183 nginxlog]# chown -R www:www /var/nginxlog
  
[root@lv183 nginxlog]# cd
  
主目录
  
[root@lv183 local]# chmod +w /usr/local/idoicancms
  
[root@lv183 local]# 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      2213  0.0  0.0   6784  2036 ?        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      2213  0.0  0.0   6784  2036 ?        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 [info] 15686#0: the configuration file /etc/nginx/nginx.conf syntax is ok
  • 2006/09/16 13:07:10 [info] 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      2213  0.0  0.0   6784  2036 ?        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 [info] 15686#0: the configuration file /etc/nginx/nginx.conf syntax is ok
  
2006/09/16 13:07:10 [info] 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      2213  0.0  0.0   6784  2036 ?        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、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-634160-1-1.html 上篇帖子: Nginx Upstream Keepalive 分析 下篇帖子: centos5下nginx+fastcgi+php+mysql搭建dz论坛(下)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表