Ubuntu下Nginx安装

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;
    }
}

  

  1. 全局配置文件: /etc/nginx/nginx.conf
  2. 站点的配置文件: /etc/nginx/sites-enabled/default
  3. 错误日志文件 : /var/log/nginx/error.log
  4. 访问日志文件 :/var/log/nginx/access.log

新增touch  +文件名

原文地址:https://www.cnblogs.com/Lolita-web/p/10574931.html