yum install nginx
配置文件默认在/etc/nginx/conf.d/default.conf,配置文件中网页根目录在/etc/share/nginx/html
下面是yii文档中推荐的nginx配置:
为了使用 Nginx,你应该已经将 PHP 安装为 FPM SAPI 了。 你可以使用如下 Nginx 配置,将 path/to/basic/web 替换为实际的 basic/web 目录, mysite.local 替换为实际的主机名以提供服务。
server {
charset utf-8;
client_max_body_size 128M;
listen 80; ## listen for ipv4
#listen [::]:80 default_server ipv6only=on; ## listen for ipv6
server_name mysite.local;
root /path/to/basic/web;
index index.php;
access_log /path/to/basic/log/access.log;
error_log /path/to/basic/log/error.log;
location / {
# Redirect everything that isn't a real file to index.php
try_files $uri $uri/ /index.php$is_args$args;
}
# uncomment to avoid processing of calls to non-existing static files by Yii
#location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
# try_files $uri =404;
#}
#error_page 404 /404.html;
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
#fastcgi_pass unix:/var/run/php5-fpm.sock;
try_files $uri =404;
}
location ~* /\. {
deny all;
}
}
修改完成后使用以下命令重启nginx完成修改
Centos6 : service nginx restart
Centos7:systemctl restart nginx
通用:
/etc/init.d/nginx start
/etc/init.d/nginx stop
/etc/init.d/nginx restart
启动报错:
nginx: [emerg] socket() [::]:80 failed (97: Address family not supported by protocol)
解决办法:
vim /etc/nginx/conf.d/default.conf
将
listen 80 default_server;
listen [::]:80 default_server;
改为:
listen 80;
#listen [::]:80 default_server;
重新启动nginx即可
另外 如果出现内部可以访问nginx,在外部无法访问的情况,可能是防火墙的问题,如果防火墙没做限制,那可能就是阿里云的安全组规则里面没有对80端口进行配置