本博文前提:
1. 有自己的雲主機
2. 有獨立的域名,如www.baidu.com
3. 使用的是linux,nginx(此處的是yum安裝的)
一、創建子域名
在自己購買域名的地方設置,購買一個域名就可以開通很多個子域名,此處展示的是Ucloud處的,開通了一個test.yourdomain.com
二、配置Nginx
在linux中執行: vim /etc/nginx/conf.d/default.conf
原安裝方式不同,路徑會不一致
最重要的是:
server_name 不要使用 localhost,換成自己的域名www.yourdomain.com,其他的復制粘貼原來的service,修改一下server_name, root就能行了(當然,你得寫進去的目錄要存在有index.html)~
此處的環境是配置了thinkphp的URL重寫,僅供參考,復制自己原來的修改就行。
server { listen 80; server_name test.yourDomain.cn; #不要使用localhost!!!! location / { root /var/www/html; index index.html index.htm index.php; if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=$1 last; break; } } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { root /var/www/html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } server { listen 80; server_name www.yourDomain.cn; location / { root /var/www/tpblog/public; index index.html index.htm index.php; if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=$1 last; break; } } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { root /var/www/tpblog/public; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
三、重啟nginx
service nginx restart
嘿嘿,希望大家都能快速解決這個問題