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
<!–
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff}
span.s1 {font-variant-ligatures: no-common-ligatures}
span.s2 {font-variant-ligatures: no-common-ligatures; color: #34bc26}
–>
[ 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 +文件名