ubuntu 安装 nginx以及apache安装配置

来源:互联网 发布:美图美妆软件 编辑:程序博客网 时间:2024/05/23 02:03

sudo apt-get update

sudo apt-get upgrade

apt-get -y install mysql-server && apt-get -y install apache2 && sudo apt-get -y install php5 libapache2-mod-php5 && /etc/init.d/apache2 restart && apt-get -y install libapache2-mod-auth-mysql && apt-get -y install php5-mysql && /etc/init.d/apache2 restart



nginx

第一步,安装nginx

apt-get update
apt-get install nginx
即可完成安装

启动nginx:
/etc/init.d/nginx start
然后就可以访问了,http://localhost/ , 一切正常!如果不能访问,先不要继续,看看是什么原因,解决之后再继续。

第二步
配置文件目录 /etc/nginx/ nginx.conf /sites-available/default
www目录 /var/www/nginx-default/

日志文件:
localhost.access.log /var/log/nginx/localhost.access.log
access.log /var/log/nginx/access.log
error.log /var/log/nginx/error.log

第三步 虚拟主机配置

------------------------------虚拟主机配置
server {
listen 80;
server_name localhost;
access_log /var/log/nginx/localhost.access.log;

location / {
root /var/www/nginx-default;
index index.php index.html index.htm;
}

location /doc {
root /usr/share;
autoindex on;
allow 127.0.0.1;
deny all;
}

location /images {
root /usr/share;
autoindex on;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/nginx-default$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}

server {
listen 80;
server_name sdsssdf.localhost.com;
access_log /var/log/nginx/localhost.access.log;

location / {
root /var/www/nginx-default/console;
index index.php index.html index.htm;
}

location /doc {
root /usr/share;
autoindex on;
allow 127.0.0.1;
deny all;
}

location /images {
root /usr/share;
autoindex on;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/nginx-default$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}

第四步
sudo ln -s 源文件 目标文件
sudo /etc/init.d/nginx restart



apache2

ubuntu下apache2建立虚拟主机
1. 打开目录 /etc/apache2/sites-available/, 发现 default 和 default-ssl 两个文件, 其中 default 是 http 虚拟主机服务的配置文件, default-ssl 是配置 https 服务使用的。 复制default为一个新文件, 文件名必须与域名一致 (如: test.drupal.com)

2. 新建 ServerName test.drupal.com
修改配置:
DocumentRoot /var/www/drupal
ErrorLog ${APACHE_LOG_DIR}/test.drupal.com-error.log
CustomLog ${APACHE_LOG_DIR}/test.drupal.com-access.log combined

3. 激活虚拟主机
sudo a2ensite test.drupal.com

4. 网站添加成功了,重启apache
sudo /etc/init.d/apache2 restart

5. 不想用了删除域名
sudo a2dissite test.drupal.com

****(不要忘记)sudo a2enmod rewrite