Discuz教程网

Nginx 完整配置示例

[复制链接]
authicon 1314学习网 发表于 2011-7-29 18:47:16 | 显示全部楼层 |阅读模式
两个虚拟主机(纯静态-html 支持)  
  1. http {
  2. : server {
  3. : listen 80;
  4. : server_name www.domain1.com;
  5. : access_log logs/domain1.access.log main;
  6. : location / {
  7. : index index.html;
  8. : root /var/www/domain1.com/htdocs;
  9. : }
  10. : }
  11. : server {
  12. : listen 80;
  13. : server_name www.domain2.com;
  14. : access_log logs/domain2.access.log main;
  15. : location / {
  16. : index index.html;
  17. : root /var/www/domain2.com/htdocs;
  18. : }
  19. : }
  20. }
复制代码

虚拟主机标准配置(简化)
  1. http {
  2. : server {
  3. : listen          80 default;
  4. : server_name     _ *;
  5. : access_log      logs/default.access.log main;
  6. : location / {
  7. : index index.html;
  8. : root  /var/www/default/htdocs;
  9. : }
  10. : }
  11. }
复制代码

在父文件夹中建立子文件夹以指向子域名
这是一个添加子域名(或是当DNS已指向服务器时添加一个新域名)的简单方法。需要注意的是,我已经将FCGI配置进该文件了。如果你只想使服务器为静态文件服务,可以直接将FCGI配置信息注释掉,然后将默认主页文件变成index.html。这个简单的方法比起为每一个域名建立一个 vhost.conf 配置文件来讲,只需要在现有的配置文件中增加如下内容:


  1. server {
  2. : # Replace this port with the right one for your requirements
  3. : # 根据你的需求改变此端口
  4. : listen       80;  #could also be 1.2.3.4:80 也可以是1.2.3.4:80的形式
  5. : # Multiple hostnames seperated by spaces.  Replace these as well.
  6. : # 多个主机名可以用空格隔开,当然这个信息也是需要按照你的需求而改变的。
  7. : server_name  star.yourdomain.com *.yourdomain.com www.*.yourdomain.com;
  8. : #Alternately: _ *
  9. : #或者可以使用:_ * (具体内容参见本维基其他页面)
  10. : root /PATH/TO/WEBROOT/$host;
  11. : error_page  404              http://yourdomain.com/errors/404.html;
  12. : access_log  logs/star.yourdomain.com.access.log;
  13. : location / {
  14. : root   /PATH/TO/WEBROOT/$host/;
  15. : index  index.php;
  16. : }
  17. : # serve static files directly
  18. : # 直接支持静态文件 (从配置上看来不是直接支持啊)
  19. : location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|html)$ {
  20. : access_log        off;
  21. : expires           30d;
  22. : }
  23. : location ~ .php$ {
  24. : # By all means use a different server for the fcgi processes if you need to
  25. : # 如果需要,你可以为不同的FCGI进程设置不同的服务信息
  26. : fastcgi_pass   127.0.0.1:YOURFCGIPORTHERE;
  27. : fastcgi_index  index.php;
  28. : fastcgi_param  SCRIPT_FILENAME  /PATH/TO/WEBROOT/$host/$fastcgi_script_name;
  29. : fastcgi_param  QUERY_STRING     $query_string;
  30. : fastcgi_param  REQUEST_METHOD   $request_method;
  31. : fastcgi_param  CONTENT_TYPE     $content_type;
  32. : fastcgi_param  CONTENT_LENGTH   $content_length;
  33. : fastcgi_intercept_errors on;
  34. : }
  35. : location ~ /\.ht {
  36. : deny  all;
  37. : }
  38. : }
复制代码






上一篇:Nginx 的中文维基
下一篇:运行和控制 Nginx - 命令行参数和信号
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-2 06:56

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

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