首先請參照ubuntu14.04 lnmp(nginx1.9+php7.0+mysql5.7)此文,將ubuntu下的lnmp環境搭建好,當你這些準備工做都作好後,咱們開始配置多域名,在本文中主要以Yii2爲基礎展開配置。javascript
修改nginx的配置文件php
#user若是不是www-data請修改成www-data user www-data; worker_processes auto; pid /run/nginx.pid; events { worker_connections 768; # multi_accept on; } http { ## # Basic Settings ## sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; # server_tokens off; # server_names_hash_bucket_size 64; # server_name_in_redirect off; include /etc/nginx/mime.types; default_type application/octet-stream; ## # SSL Settings ## ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE ssl_prefer_server_ciphers on; ## # Logging Settings ## access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; ## # Gzip Settings ## gzip on; gzip_disable "msie6"; # gzip_vary on; # gzip_proxied any; # gzip_comp_level 6; # gzip_buffers 16 8k; # gzip_http_version 1.1; # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; ## # Virtual Host Configs ## include /etc/nginx/conf.d/*.conf; #添加以下包含文件夾,易方便接下來的配置文件統一管理和修改 include /etc/nginx/sites-enabled/*; }
參照如上修改後,咱們的配置文件在 /etc/nginx/sites-enabled/
下面;
nginx默認的網站根目錄在/usr/share/nginx/html
,因此咱們要新建文件夾並給他權限,執行以下命令:css
cd /var/www
若是不存在則用下面的命令:html
sudo mkdir -p /var/www
虛擬主機配置以下java
server { listen 80 default_server; // 全部虛擬主機中只能有一個默認主機 charset utf-8; client_max_body_size 128M; index index.php index.html index.htm; server_name localhost; # 域名 www.xxx.com root /www # 項目文件的入口文件夾 location / { try_files $uri $uri/ /index.php?$args; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 location ~ \.php$ { include fastcgi_params; fastcgi_pass unix:/var/run/php5-fpm.sock; } location ~ /\.(ht|svn|git) { deny all; } }
啓動nginxnode
sudo nginx -s reload
若是啓動不成功,用以下命令檢查問題:mysql
sudo nginx -t
根據提示調試解決。
若是還不行,檢查 /etc/nginx/fastcgi_params ,下面詳細說明。nginx
檢查fastcgi_params文件git
sudo vim /etc/nginx/fastcgi_params
sql
查看是否有以下代碼:
fastcgi_param PATH_INFO $fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
沒有則加上。
提示
fastcgi_pass 127.0.0.1:9000; #也能夠設置爲這個,但要把 /etc/php5/fpm/pool.d 裏面的 listen = 127.0.0.1:9000 把下面這個語句註釋掉 ; listen = /var/run/php5-fpm.sock 這個語句對應的是這個 fastcgi_pass unix:/var/run/php5-fpm.sock;