問題描述:
我在同一伺服器下同目錄下配置了兩個字域名專案,環境是laravel5.2/php5.6,在瀏覽器中輸入域名2之後,程式開始進入域名2 的專案入口檔案index.php開始執行,之後就開始跑的是域名1下的專案.
配置詳細如下:
域名1:a.test.com 對應的專案: /usr/share/nginx/html/a
域名2:b.test.com 對應的專案: /usr/share/nginx/html/b
Nginx 配置如下:
Nginx.conf
user www-data; worker_processes 4; 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; ## # 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/x-javascript text/xml application/xml application/xml+rss text/javascript; ## # nginx-naxsi config ## # Uncomment it if you installed nginx-naxsi ## #include /etc/nginx/naxsi_core.rules; ## # nginx-passenger config ## # Uncomment it if you installed nginx-passenger ## #passenger_root /usr; #passenger_ruby /usr/bin/ruby; ## # Virtual Host Configs ## include /etc/nginx/sites-enabled/*; include /etc/nginx/conf.d/*.conf; #include /etc/nginx/sites-enabled/*; client_max_body_size 5m; }
Conf.d/ a.conf域名、b.conf域名 配置如下
server { listen 80; server_name a.test.com; #server_name b.test.com; client_max_body_size 500m; #charset koi8-r; #access_log logs/yyhc.gytcare.com access.log combined; index index.php index.html; root /usr/share/nginx/html/a/public; #root /usr/share/nginx/html/b/public; location / { try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } # if (!-e $request_filename){ # rewrite ^/(.*)$ /index.php/$1 last; # break; # } }
hosts 配置
# 101.201.36.46 localhost 101.201.36.46 a.test.com 101.201.36.46 b.test.com #127.0.0.1 localhost #127.0.1.1 localhost.localdomain localhost # The following lines are desirable for IPv6 capable hosts ::1 localhost ip6-localhost ip6-loopback ff02::1 ip6-allnodes ff02::2 ip6-allrouters 10.46.178.159 iZ25pxsvearZ
開始執行
在瀏覽器中輸入域名2之後,程式開始進入域名2 的專案入口檔案index.php開始執行,之後就開始跑的是域名1下的專案.
```php require __DIR__.'/../bootstrap/autoload.php'; $app = require_once __DIR__.'/../bootstrap/app.php'; $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class); dd($kernel); $response = $kernel->handle( $request = Illuminate\Http\Request::capture() ); $response->send(); $kernel->terminate($request, $response); ```
dd($kernel); 列印出來的結果 basepath指向的是域名a 的目錄
Kernel {[#25 ▼] ... #app: Application {[#2 ▼] #basePath: "/usr/share/nginx/html/a" #hasBeenBootstrapped: false ...