Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6550144
  • 博文数量: 1159
  • 博客积分: 12444
  • 博客等级: 上将
  • 技术积分: 12570
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-13 21:34
文章分类

全部博文(1159)

文章存档

2016年(126)

2015年(350)

2014年(56)

2013年(91)

2012年(182)

2011年(193)

2010年(138)

2009年(23)

分类: Android平台

2015-11-21 21:56:38


CentOS 7 安装Nginx-1.9.2


1、安装必备工具:

yum -y install gcc gcc-c++ autoconf automake
yum -y install zlib zlib-devel openssl openssl-devel pcre-devel

说明:
pcre: 用来作地址重写的功能。
zlib:nginx 的gzip模块,传输数据打包,省流量(但消耗资源)。
openssl:提供ssl加密协议。

2、新建一个系统级用户组和匿名用户,以及下面编译时使用

groupadd -r nginx
useradd -s /sbin/nologin -g nginx -r nginx

3、下载nginx

wget
tar -zxvf nginx-1.9.7.tar.gz
cd nginx-1.9.7/

4、编译nginx

[root@localhost nginx-1.9.7]#


点击(此处)折叠或打开

  1. ./configure \
  2. --prefix=/etc/nginx \
  3. --sbin-path=/usr/sbin/nginx \
  4. --conf-path=/etc/nginx/nginx.conf \
  5. --error-log-path=/var/log/nginx/error.log \
  6. --http-log-path=/var/log/nginx/access.log \
  7. --pid-path=/var/run/nginx.pid \
  8. --lock-path=/var/run/nginx.lock \
  9. --http-client-body-temp-path=/var/cache/nginx/client_temp \
  10. --http-proxy-temp-path=/var/cache/nginx/proxy_temp \
  11. --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
  12. --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
  13. --http-scgi-temp-path=/var/cache/nginx/scgi_temp \
  14. --user=nginx \
  15. --group=nginx \
  16. --with-http_ssl_module \
  17. --with-http_realip_module \
  18. --with-http_addition_module \
  19. --with-http_sub_module \
  20. --with-http_dav_module \
  21. --with-http_flv_module \
  22. --with-http_mp4_module \
  23. --with-http_gunzip_module \
  24. --with-http_gzip_static_module \
  25. --with-http_random_index_module \
  26. --with-http_secure_link_module \
  27. --with-http_stub_status_module \
  28. --with-http_auth_request_module \
  29. --with-mail \
  30. --with-mail_ssl_module \
  31. --with-file-aio \
  32. --with-ipv6 \
  33. --with-cc-opt='-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'

[root@localhost nginx-1.9.7]# make -j4 && make install
[root@localhost nginx-1.9.7]# mkdir -p /var/cache/nginx/client_temp
[root@localhost nginx-1.9.7]# systemctl stop httpd.service
[root@localhost nginx-1.9.7]# nginx -c /etc/nginx/nginx.conf

5、Nginx 控制脚本

[root@localhost nginx-1.9.7]# gedit /usr/lib/systemd/system/nginx.service

点击(此处)折叠或打开

  1. [Unit]
  2. Description=nginx - high performance web server
  3. Documentation=http://nginx.org/en/docs/
  4. After=network.target remote-fs.target nss-lookup.target
  5.    
  6. [Service]
  7. Type=forking
  8. PIDFile=/run/nginx.pid
  9. ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
  10. ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
  11. ExecReload=/bin/kill -s HUP ${MAINPID}
  12. ExecStop=/bin/kill -WINCH ${MAINPID}
  13. PrivateTmp=true
  14.    
  15. [Install]
  16. WantedBy=multi-user.target

6、修改权限
[root@localhost nginx-1.9.7]# chmod +x /usr/lib/systemd/system/nginx.service
[root@localhost nginx-1.9.7]# systemctl enable nginx.service
ln -s '/usr/lib/systemd/system/nginx.service' '/etc/systemd/system/multi-user.target.wants/nginx.service'

# 会在/etc/systemd/system/multi-user.target.wants/目录下新建一个/usr/lib/systemd/system/nginx.service 文件的链接。
 
7、使用下面的指令来控制nginx

systemctl start nginx.service
systemctl reload nginx.service
systemctl restart nginx.service
systemctl stop nginx.service
 
8、查看日志
journalctl -f -u nginx.service


++++++++++++++++++++++++++++++++++
[root@localhost nginx]# gedit /etc/nginx/nginx.conf

点击(此处)折叠或打开

  1. #user nobody;
  2. worker_processes 1;

  3. #error_log logs/error.log;
  4. #error_log logs/error.log notice;
  5. #error_log logs/error.log info;

  6. #pid logs/nginx.pid;


  7. events {
  8.     worker_connections 1024;
  9. }


  10. http {
  11.     include mime.types;
  12.     default_type application/octet-stream;

  13.     #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  14.     # '$status $body_bytes_sent "$http_referer" '
  15.     # '"$http_user_agent" "$http_x_forwarded_for"';

  16.     #access_log logs/access.log main;

  17.     sendfile on;
  18.     #tcp_nopush on;

  19.     #keepalive_timeout 0;
  20.     keepalive_timeout 65;

  21.     #gzip on;

  22.     server {
  23.         listen 80;
  24.         server_name localhost;

  25.         #charset koi8-r;

  26.         #access_log logs/host.access.log main;

  27.         location / {
  28.             root html;
  29.             index index.html index.htm;
  30.         }

  31.     location ~ \.cgi$ {
  32.         fastcgi_pass 127.0.0.1:8088;
  33.         fastcgi_index index.cgi;
  34.         fastcgi_param SCRIPT_FILENAME fcgi$fastcgi_script_name;
  35.         include fastcgi_params;
  36.     }

  37.         #error_page 404 /404.html;

  38.         # redirect server error pages to the static page /50x.html
  39.         #
  40.         error_page 500 502 503 504 /50x.html;
  41.         location = /50x.html {
  42.             root html;
  43.         }

  44.         # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  45.         #
  46.         #location ~ \.php$ {
  47.         # proxy_pass http://127.0.0.1;
  48.         #}

  49.         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  50.         #
  51.         #location ~ \.php$ {
  52.         # root html;
  53.         # fastcgi_pass 127.0.0.1:9000;
  54.         # fastcgi_index index.php;
  55.         # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  56.         # include fastcgi_params;
  57.         #}

  58.         # deny access to .htaccess files, if Apache's document root
  59.         # concurs with nginx's one
  60.         #
  61.         #location ~ /\.ht {
  62.         # deny all;
  63.         #}
  64.     }


  65.     # another virtual host using mix of IP-, name-, and port-based configuration
  66.     #
  67.     #server {
  68.     # listen 8000;
  69.     # listen somename:8080;
  70.     # server_name somename alias another.alias;

  71.     # location / {
  72.     # root html;
  73.     # index index.html index.htm;
  74.     # }
  75.     #}


  76.     # HTTPS server
  77.     #
  78.     #server {
  79.     # listen 443 ssl;
  80.     # server_name localhost;

  81.     # ssl_certificate cert.pem;
  82.     # ssl_certificate_key cert.key;

  83.     # ssl_session_cache shared:SSL:1m;
  84.     # ssl_session_timeout 5m;

  85.     # ssl_ciphers HIGH:!aNULL:!MD5;
  86.     # ssl_prefer_server_ciphers on;

  87.     # location / {
  88.     # root html;
  89.     # index index.html index.htm;
  90.     # }
  91.     #}

  92. }











阅读(1069) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~