您的位置:首页 > 运维架构 > Nginx

阿里云服务器cent0S安装web环境PHP+MySql+Nginx,给nginx添加网站

2015-09-11 15:16 801 查看
下载一键安装包:

http://market.aliyun.com/product/12-121590002-cmgj000262.html?spm=5176.7150518.1996836753.5.ZoE32o

在服务器安装rz命令

yum install lrzsz

rz 选择要上传文件sh.zip

安装解压命令:

yum install unzip #本机已经安装了.所以这里不安装

解压

unzip -x sh.zip #解压后脚本的权限不够

chmod -R 755 sh #-R 递归将目录里面所有文件权限都改为755

在sh目录下执行

./install.sh

安装完毕后,检查

ps -ef|grep nginx

ps -ef|grep mysql

在sh目录下执行

cat account.log #查看mysql账号密码

FTP:

account:www

password:zzzzzz

MySQL:

account:root

password:zzzzzz

netstat -nat #查看3306端口有没有listen

rpm -q mysql #查询发现是mysql-server没有安装

yum install mysql-server #安装mysql-server服务

service mysqld restart

mysql #查看mysql信息

mysql -p3306 -u用户名 -p密码 #登录mysql

mysql -p3306 -uroot -pzzzzzzz

use mysql #进入mysql这个数据库

show tables

desc user

select Host,User,Password from user; #查看数据库用户

exit #退出

mysql -p3306 -u用户名 -p密码 #登录mysql

use mysql

update user set Host='%' where Host='localhost' #%表示任意的,这样就可以在其他电脑连接ip

flush privileges #刷新

在外部电脑:

浏览器输入:服务器ip #对phpwind进行设置

Nginx添加网站:

在服务器目录: /alidata/server 有下面目录:

mysql mysql-5.6.21 nginx nginx-1.4.4 php php-5.5.7

进入目录: /alidata/server/nginx/conf

cat nginx.conf #这个文件找到最后一行

include /alidata/server/nginx/conf/vhosts/*.conf;

#包含了vhosts下面所有配置文件,一个网站一个conf

进入目录:alidata/server/nginx/conf/vhosts/

查看文件: cat phpwind.conf

文件开始:::::

server {

listen 80;

server_name localhost;
#这里localhost,所以浏览器输入ip可以访问,如果输入www.xxx.com,浏览器就只能输入相关域名

index index.html index.htm index.php;

root /alidata/www/phpwind;

location ~ .*\.(php|php5)?$

{

#fastcgi_pass unix:/tmp/php-cgi.sock;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

include fastcgi.conf;

}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

{

expires 30d;

}

location ~ .*\.(js|css)?$

{

expires 1h;

}

#伪静态规则

include /alidata/server/nginx/conf/rewrite/phpwind.conf;

access_log /alidata/log/nginx/access/phpwind.log;

文件结束:::::::::

添加站点:www.paidaxue.com

cp default.conf.bak paidaxue.conf

修改文件:vim paidaxue.conf

修改: server_name localhost;

修改为:

server_name www.paidaxue.com;

修改: root /alidata/www/phpwind;

修改为:

root /alidata/www/paidaxue.com;

修改: 如果原来没有这一段就忽略修改

log_farmat aliyun '$remote_addr - $remote_user [$time_local] "$request" '

'$status $body_bytes_sent "$http_referer" '

' "$http_user_agent" "$http_x_forwarded_for"';

修改为:

log_farmat paidaxue '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
' "$http_user_agent" "$http_x_forwarded_for"';

修改:

access_log /alidata/log/nginx/access/default.log;

修改为:

access_log /alidata/log/nginx/access/paidaxue.com;

保存

进入目录:

/alidata/server/nginx/sbin/nginx -s reload #重启nginx

浏览器输入:www.paidaxue.com #会显示404not found 因为没有对应目录

新建目录:alidata/www/paidaxue.com

mkdir -p /alidata/www/paidaxue.com

查看新建的目录: #paidaxue.com是在root的用户,root用户组中

drwxr-xr-x 2 root root 4096 Jan 13 17:00 paidaxue.com

drwxr-xr-x 26 www www 4096 Jan 13 16:15 phpwind

浏览器输入:www.paidaxue.com #会显示403Forbidden 因为没有权限访问

所以要对 paidaxue.com的权限进行更改,变成和下面一样的www

cd /alidata/www/

chown -R www:www /alidata/www/paidaxue.com

浏览器输入:www.paidaxue.com #会显示403Forbidden 因为里面没有文件

cd /alidata/www/paidaxue.com

在上面文件夹新建index.html

浏览器输入:www.paidaxue.com #正常
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: