Nginx Website Server Building Example

Source: Internet
Author: User
Tags sendfile website server

Nginx is an open source high-performance HTTP Server and a back-up proxy server.

Download, compile, install the module:

[[email protected] nginx-1.4.0] #wget  http://nginx.org/download/nginx-1.4.0.tar.gz[[email  PROTECTED] NGINX-1.4.0] #tar  -xzf nginx-1.4.0.tar.gz -C /usr/src/[[email  PROTECTED] NGINX-1.4.0] #yum  -y install gcc pcre pcre-devel gcc openssl  >openssl-devel gd gd-devel perl perl-ExtUtils-Embed[[email protected]  NGINX-1.4.0] #cd  /usr/src/nginx-1.4.0/[[email protected] nginx-1.4.0]# ./configure -- prefix=/usr/local/nginx > --with-ipv6 > --with-http_ssl_module > -- with-http_realip_module > --with-http_addition_module > --with-http_dav_module  > --with-http_flv_module > --with-http_mp4_module > --with-http_gzip_static_ Module > --with-http_perl_module > --with-mail > --with-mail_ssl_module [[EMAIL PROTECTED] NGINX-1.4.0] #make  && make install 

Each module introduction (code Word too much, Baidu solves it):

The server is installed in the /usr/local/nginx/ directory

Nginx Common management commands:

[Email protected] nginx]#/usr/local/nginx/sbin/nginx #启动主程序 [[email protected] xyz]#/usr/local/nginx/sbin/nginx-c >/usr/local/nginx/conf/nginx.conf# Specify the configuration file to start the main program [[email protected] nginx]#/usr/local/nginx/sbin/nginx-s stop# Close main program [[email protected] nginx]#/usr/local/nginx/sbin/nginx-s reload# Reload settings

Configuration file Resolution:

[[email protected] nginx]# cat conf/nginx.conf  #设置用户与组user   nobody;# Number of start subprocess worker_processes  1;  #error_log   logs/error.log; #error_log   logs/ error.log  notice; #错误日志文件, and log level. error_log  logs/error.log  info; #进程号保存文件pid          logs/nginx.pid;  events {#每个进程可以处理的连接数, limited by the system file handle     worker_ connections  1024;}   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" ';      #access_log    logs/access.log  main; #是否调用sendfile () for data replication, sendfile () copy data is done at the kernel level, so it will be more than the normal read, Write more efficiently sendfile        on; #开启后的服务器的响应头部信息产生独立的数据包发送, a response header a package      tcp_nopush     on;  #保持连接的超时时间     keepalive _timeout  65;  #是否启用压缩功能 to save more traffic when the page is compressed     gzip  on; # Defining a virtual host with server server {#服务器监听的端口         listen        80; #访问域名         server_name   daqijiance.com *.daqijiance.com; #编码格式, if the page encoding differs from this setting, it will be automatically transcoded           #charset  koi8-r; #设置虚拟主机的访问日志         access_log  logs/daqijiance.com. log  main; #对url进行匹配         location / {#设置网页的根路径, Using a relative path, HTML refers to the installation path under Nginx             root    html/daqijiance; #首页文件, first find index.html, if not, then find index.htm             index  index.html index.htm index.aspx;         }          #error_page   404               /404.html;          # redirect server error pages to the  static page /50x.html        #         error_page   500 502 503 504  /50x.html;        location  = /50x.html {            root    html;        }          # proxy the PHP scripts to Apache listening on  127.0.0.1:80        #        # location ~ \.php$ {        #     proxy_pass   http://127.0.0.1;        #}          # pass the php scripts to fastcgi  server listening on 127.0.0.1:9000        #          #location  ~ \.php$ {        #     root           html;         #    fastcgi_pass   127.0.0.1:9000;         #    fastcgi_index  index.php;         #    fastcgi_param  SCRIPT_FILENAME   /scripts$fastcgi_script_name;        #     include        fastcgi_params;         #}         # deny access to . Htaccess files, if apache ' s document root         # concurs with Nginx ' s one        #         location ~ /\.ht {             deny  all;        }    }       # another virtual host using mix of ip-,  name-, and port-based configuration    #     server {        listen        80;        server_name  hbgk.com *.hbgk.com  hebeigankong.com *.hebeigankong.com;             location / {            root    html/hebeigankong;            index  index.html index.htm  index.aspx;        }    }      server {        listen        80;        server_name  yiyuanjiance.com *. yiyuanjiance.com;         location / {             root html/yiyuanjiance/;             index index.html index.htm index.aspx;         }    }       # https server        server {         listen       443;        server_name   hbu.cn hbu.edu.cn *.hbu.cn *.hbu.edu.cn;          ssl                   on;        ssl_certificate       cert.pem;        ssl_certificate_key  cert.key;          ssl_session_timeout  5m;          ssl_protocols  SSLv2 SSLv3 TLSv1;         ssl_ciphers  high:!anull:! md5;        ssl_prefer_server_ciphers   on;          location / {            root   html/hbu;             index  index.html index.htm  Index.aspx;        }    } } [[email  protected] nginx]# mkdir /usr/local/nginx/html/{daqijiance,hebeigankong,yiyuanjiance}[[ email protected] nginx]# echo  "Daqijiance.com"  > /usr/local/nginx/html/ daqijiance/index.html[[email protected] nginx]# echo  "Hebeigankong.com"  > / usr/local/nginx/html/hebeigankong/index.html[[email protected] nginx]# echo  " Yiyuanjiance.com " > /usr/local/nginx/html/yiyuanjiance/index.html

The above example can be based on the routing domain to jump to different Web pages, that is, multiple sites bound to the same IP,Nginx web server monitoring Port implementation of different visiting domain names, return to different home page.

In fact, this test is generally modified by the DNS Domain name resolution, if there is no DNS Domain name resolution, you can also modify the hosts file by way of implementation.

[Email protected] xyz]# cat/etc/hosts127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain6192.168.50.157 www.daqijiance.com Www.hebeiganko ng.com www.yiyuanjiance.com daqijiance.com hebeigankong.com yiyuanjiance.com hbgk.com hbu.cn hbu.edu.cn www.hbu.cn www.hbu.edu.cn

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/44/55/wKioL1Pgo07RbRAdAADHBHof7-s930.jpg "title=" Picture 1.png "alt=" Wkiol1pgo07rbradaadhbhof7-s930.jpg "/>


This article is from the "Noogel" blog, so be sure to keep this source http://noogel.blog.51cto.com/9222825/1536050

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.