unijun 发表于 2018-11-9 07:32:23

12.6 Nginx安装 12.7 默认虚拟主机 12.8 Nginx用户认证 12.9 Nginx-martinLIU的博客

12.6 Nginx安装

  # chkconfig --add nginx
  # chkconfig nginx on
  # /usr/local/nginx/sbin/nginx -t
  nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
  nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
  # /etc/init.d/nginx start
  -bash: /etc/init.d/nginx: 权限不够
  # chmod 755 /etc/init.d/nginx
  # /etc/init.d/nginx start
  Reloading systemd:                                       [确定]
  Starting nginx (via systemctl):                            [确定]
  # netstat -lntp |grep 80
  tcp      0      0 0.0.0.0:80            0.0.0.0:               LISTEN      3729/nginx: master
  # ps -aux |grep nginx
  root       37290.00.020496   628 ?      Ss   23:23   0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
  nobody   37300.00.3229403200 ?      S    23:23   0:00 nginx: worker process
  nobody   37310.00.3229403200 ?      S    23:23   0:00 nginx: worker process
  root       37360.00.0 112676   956 pts/0    R+   23:29   0:00 grep --color=auto nginx
  # curl localhost/1.php
  this is nginx page test.#
12.7 默认虚拟主机

  # mkdir /data/wwwroot/default
  # ls !$
  ls /data/wwwroot/default
  # vim /data/wwwroot/default/index.html
  # /usr/local/nginx/sbin/nginx -t
  nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
  nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

  # /usr/local/nginx/sbin/nginx -s>  # !curl
  curl -x127.0.0.1:80 aaa.com
  This is the default site.
12.8 Nginx用户认证

  # /usr/local/nginx/sbin/nginx -t
  nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
  nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

  # /usr/local/nginx/sbin/nginx -s>  # mkdir /data/wwwroot/test.com
  # echo "test.com" > /data/wwwroot/test.com/index.html
  # curl -I -x127.0.0.1:80 test.com
  HTTP/1.1 401 Unauthorized
  Server: nginx/1.12.1
  Date: Tue, 13 Mar 2018 16:21:36 GMT
  Content-Type: text/html
  Content-Length: 195
  Connection: keep-alive
  WWW-Authenticate: Basic realm="Auth"
  # curl -umartin:123456 -x127.0.0.1:80 test.com
  test.com
12.9 Nginx域名重定向

  # vim test.com.conf
  # cat test.com.conf
  server
  {
  listen 80;
  server_name test.com test1.com test2.com;
  index index.html index.htm index.php;
  root /data/wwwroot/test.com;
  if ($host != 'test.com' ) {
  rewrite^/(.*)$http://test.com/$1permanent;
  }
  }
  # /usr/local/nginx/sbin/nginx -t
  nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
  nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

  # /usr/local/nginx/sbin/nginx -s>  # curl -x127.0.0.1:80 test1.com/123.txt -I
  HTTP/1.1 301 Moved Permanently
  Server: nginx/1.12.1
  Date: Tue, 13 Mar 2018 16:37:07 GMT
  Content-Type: text/html
  Content-Length: 185
  Connection: keep-alive
  Location: http://test.com/123.txt

页: [1]
查看完整版本: 12.6 Nginx安装 12.7 默认虚拟主机 12.8 Nginx用户认证 12.9 Nginx-martinLIU的博客