1.1 安装Nginx
$sudo apt-get install nginx
Ubuntu安装之后的文件结构大致为:
所有的配置文件都在/etc/nginx下,并且每个虚拟主机已经安排在了/etc/nginx/sites-available下
程序文件在/usr/sbin/nginx
日志放在了/var/log/nginx中
并已经在/etc/init.d/下创建了启动脚本nginx
默认的虚拟主机的目录设置在了/var/www/nginx-default (有的版本 默认的虚拟主机的目录设置在了/var/www, 请参考/etc/nginx/sites-available里的配置)
1.2 启动Nginx
$sudo /etc/init.d/nginx start
[ ok ] Starting nginx (via systemctl): nginx.service.
Nginx的配置文件是 cd /etc/nginx/nginx.conf
vim nginx.conf
cd /etc/nginx/sites-enabled
vim default
server {#服务启动时监听的端口listen 80 default_server;listen [::]:80 default_server;#服务启动时文件加载的路径root /var/www/html/wordpress;#默认加载的第一个文件index index.php index.html index.htm index.nginx-debian.html;#页面访问域名,如果没有域名也可以填写_server_name www.xiexianbo.xin;location / {#页面加载失败后所跳转的页面try_files $uri $uri/ =404;}#以下配置只服务于php# 将PHP脚本传递给在127.0.0.1:9000上监听的FastCGI服务器location ~ \.php$ {include snippets/fastcgi-php.conf;# With php7.0-cgi alone:#fastcgi_pass 127.0.0.1:9000;# With php7.0-fpm:fastcgi_pass unix:/run/php/php7.0-fpm.sock;}# 如果Apache的文档为root,则拒绝访问.htaccess文件location ~ /\.ht {deny all;}
}
- 全局配置文件: /etc/nginx/nginx.conf
- 站点的配置文件: /etc/nginx/sites-enabled/default
- 错误日志文件 : /var/log/nginx/error.log
- 访问日志文件 :/var/log/nginx/access.log
新增touch +文件名