1) Nginx
yum install nginx
vim /etc/nginx/conf.d/default.conf
nginx -t
service nginx start
vim /etc/nginx/conf.d/your-domain.conf
server {
listen 80;
server_name your-domain;
root /var/www/html;
access_log /var/log/nginx/your-domain_access.log;
error_log /var/log/nginx/your-domain_error.log;
index index.php index.html index.htm;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
include fastcgi_params;
}
location / {
autoindex on;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
service nginx reload
chkconfig nginx on
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
因为阿里云默认不允许公网通过 HTTP、HTTPS 等服务,因此还需要在安全组那边进行配置;详见:应用案例
1. 登录 云服务器管理控制台。
2. 找到要配置的实例。
3. 打开实例的 本实例安全组,然后单击 配置规则。
4. 单击 公网入方向,然后单击 快速创建规则。
5. 添加安全组规则如下:
网卡类型:如果是经典网络,选择 公网。如果是 VPC 网络,不需要选择。
规则方向:入方向。
授权策略:允许。
协议类型 和 端口范围:选择 HTTP 服务的 TCP 80 端口,HTTPS 的 443 端口,或者自定义 TCP 8080 端口(如图所示)。
授权对象:0.0.0.0/0,表示允许所有地址访问。
优先级:1,表示安全规则中优先级最高,数字越小优先级越高。
到这里,就可以通过IP访问Nginx了;
2) PHP
rpm -Uvh http:
rpm -Uvh http:
yum install --enablerepo=remi --enablerepo=remi-php56 php php-bcmath php-cli php-common php-devel php-fpm php-gd php-imap php-ldap php-mbstring php-mcrypt php-pecl-apc php-mysqlnd php-mysql php-odbc php-pdo php-gd php-mcrypt php-pear php-pecl-igbinary php-xml php-xmlrpc
service php-fpm start
service php-fpm restart
service php-fpm status
chkconfig php-fpm on
vim /var/www/html/index.php
<?php
phpinfo();
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
记住,nginx的域名配置如果没有下面的内容(就是说,碰到.php结尾的文件,传递给后方127.0.0.1的9000端口上),会导致nginx无法解析PHP文件
location ~ .*\.php$ {
fastcgi_pass 127.0.0.1:9000;
}
3) MySQL
yum -y install mysql-server
service mysqld start
service mysqld restart
chkconfig mysqld on
mysql_secure_installation
Set root password? [Y/n]
service mysqld restart
mysql -u root -p
flush privileges;
use mysql;
update user set host='%' where user='root' and host='localhost';
select host, user from user;
exit;