一聚教程网:一个值得你收藏的教程网站

热门教程

ubuntu配置apache与nginx虚拟主机详解

时间:2022-06-30 19:31:08 编辑:袖梨 来源:一聚教程网

apache虚拟主机配置

 代码如下 复制代码

#创建目录#
$mkdir /var/www/phperstar

#创建虚拟主机配置文件#
$cd /etc/apache2/sites-enabled/
$vi websitename

#复制一下内容,贴入配置文件,保存退出#

        ServerAdmin webmaster@localhost
        ServerName www.111com.net    #改成自己想用的域名#
        DocumentRoot /var/www/phperstar  #放置程序用的目录#
       
                Options FollowSymLinks
                AllowOverride None
       

          #放置程序用的目录#
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
       

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
       
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
       

        ErrorLog ${APACHE_LOG_DIR}/www.111com.net_error.log   #错误日志目录#

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/www.111com.net_access.log combined  #访问日志目录#

#启用配置文件#
$cd /etc/apache2
$sudo a2ensite websitename
Enabling site phperstar.
To activate the new configuration, you need to run:
  service apache2 reload

#重启apache#
$sudo service apache2 reload
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[ OK ]

#绑定hosts#
$vi /etc/hosts

#加入下面自己配置的域名,保存推出#
127.0.1.1  www.111com.net

然后浏览器访问域名,就行了

ubuntu nginx配置虚拟主机,目录

在/etc/nginx/sites-available/ 创建www.111com.net(你的dns的名字)文件

 代码如下 复制代码

server {
       listen   80; ## listen for ipv4; this line is default and implied
     #listen   [::]:80 default ipv6only=on; ## listen for ipv6

        root /home/angelmylove/zendphp/MyAngelMyLove/; #你网站所在目录的绝对路径
         index index.php index.html index.htm; #目录索引

        # Make site accessible from http://localhost/
            server_name  www.111com.net; #网站的域名

     location / {
                index index.html index.htm index.php;  #目录索引
                  rewrite ^/(.*)$ /index.php/$1 last;  #Rewrite 隐藏index.php
      }

#使nginx支持php
    location ~ ^(.+.php)(.*)$ {
       fastcgi_pass 127.0.0.1:9000;
       fastcgi_index index.php;
       fastcgi_split_path_info ^(.+.php)(.*)$;
       fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
   }
}

在etc/hosts的文件里面添加 127.0.0.1  www.111com.net

 代码如下 复制代码

service php5-fpm restart
service  nginx restart

注意:这种配置有可能会导致包含文件的路径出错

热门栏目