Ubuntu--nginx配置虚拟主机

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/myhuashengmi/article/details/73819663

假定我们的虚拟主机存放目录为var/www/exp

创建nginx虚拟主机www.exp.com文件配置(PHP域根据本机的PHP应用情况配置)

 vim /etc/nginx/sites-available/www.exp.com
 #Log Format
   log_format access_exp '$time_iso8601 | $remote_addr | $request | $status | $request_body | $http_referer | $http_user_agent | $http_x_forwarded_for';

   server {
       listen 80;

       root /var/www/exp/web;

      index index.php index.html index.htm;
      server_name www.exp.com;

      # log
      access_log /var/log/nginx/www.exp.com.access.log access_exp;
      error_log /var/log/nginx/www.exp.com.error.log;

      #location /www.exp.com/ {

      location / {
          #try_files $uri $uri/ /www.exp.com/index.php?$args;
          try_files $uri $uri/ /index.php?$args;
          client_max_body_size    10m;
      }

      location ~ /(protected|\.git|framework|nbproject|themes/\w+/views|index-test\.php) {
          deny all;
      }

      location = /favicon.ico {
          log_not_found off;
          access_log off;
}

      location = /robots.txt {
          log_not_found off;
          access_log off;
      }

      location ~* \.(js|css|png|jpg|jpeg|gif|ico)\$ {
          expires max;
          log_not_found off;
          access_log off;
      }

      location ~ /\.ht {
          deny all;
      }

      location ~ \.php\$ {
          fastcgi_pass   unix:/var/run/php5-fpm.sock;
          fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
          include        fastcgi_params;
      }
  }

因为nginx的的主配置文件nginx.conf会自动应用启用的站点 - 中的配置文件,所以我们需要在启用网站-中建立一个www.exp.com文件的链接

cd /etc/nginx/sites-enabled
ln -s ../sites-available/www.exp.com  www.exp.com

重新加载nginx的使配置生效 nginx -s reload

至此,nginx虚拟主机就已配置完成,可在浏览器中访问测试。
在部署项目的过程中需要主要以下几点:

  1. 确保项目的缓存文件如css js 有相应的rwx权限
  2. 确保项目的日志文件有相应的rwx的权限
  3. 确保web/index.php在项目部署的过程中不会被git给过滤

    附上参考文章链接:http://blog.csdn.net/stwstw0123/article/details/47122191

猜你喜欢

转载自blog.csdn.net/myhuashengmi/article/details/73819663
今日推荐