時(shí)間:2023-05-25 01:39:02 | 來(lái)源:網(wǎng)站運(yùn)營(yíng)
時(shí)間:2023-05-25 01:39:02 來(lái)源:網(wǎng)站運(yùn)營(yíng)
小白學(xué)習(xí)之路-從零開(kāi)始用SSH在Linux服務(wù)器上構(gòu)建Wordpress網(wǎng)站:最近學(xué)習(xí)網(wǎng)站開(kāi)發(fā),由最簡(jiǎn)單的東西開(kāi)始一步一步入門(mén),不知不覺(jué)一個(gè)月間就學(xué)到了我難以想象多的知識(shí). 雖然Wordpress會(huì)被一些高端開(kāi)發(fā)者鄙視, 尤其是它是基于PHP的(其實(shí)我也不適應(yīng),因?yàn)槲沂侵饕獙W(xué)習(xí)Python研發(fā)的), 但是作為一個(gè)領(lǐng)你入門(mén)的師父,Wordpress毫無(wú)疑問(wèn)是把你從零基礎(chǔ)領(lǐng)到高端的好師父! 本文就是我這幾天以Wordpress為契機(jī),研究在各種網(wǎng)絡(luò)服務(wù)器的成果. 內(nèi)置一些常見(jiàn)的坑及跳坑的方法.要搭建wordpress,首先得有個(gè)VPS吧.
SSH
命令就可以了.Putty.exe
.用它就ok.root@username:~# sudo apt-get install php5-fpm nginx mysql-server php5-mysql雖然不知道這幾個(gè)依賴包的順序有什么講究(看起來(lái)好像有一點(diǎn)點(diǎn)邏輯性?).
service nginx start
,就啟動(dòng)了nginx服務(wù)器.Welcome to nginx!
好方便!!/var/www/html
,所以很好找.wget http://wordpress.org/latest.zip
.unzip
解壓(提示沒(méi)有unzip程序,則apt-get install unzip
).chmod 777 -R /var/www/html/wpblog
, 777代表最高權(quán)限.chown
,雖然我不懂區(qū)別,但也沒(méi)發(fā)現(xiàn)有什么問(wèn)題.mysql -u root -p
登進(jìn)mysql,然后輸入密碼,進(jìn)入后create database 數(shù)據(jù)庫(kù)名;
,就OK了.wp-config.php
文件了.http://abc.com/wpblog/
后,會(huì)出現(xiàn)403 Forbidden
字樣./etc/nginx/sites-available/
下的default
文件.default-backup
文件.default
文件,遵照nginx語(yǔ)法改了幾行.root@username:~# sudo service nginx restartJob for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
然后不管是start還是restart都是這句話.納悶了.就按照出錯(cuò)指示,輸入了systemctl status nginx.service
:root@username:~# systemctl status nginx.service nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Tue 2020-10-23 08:27:51 EST; 22s ago Process: 8508 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS) Process: 8609 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE) Main PID: 7194 (code=exited, status=0/SUCCESS)
完全看不懂...當(dāng)然后來(lái)也證明,這個(gè)對(duì)我排除錯(cuò)誤完全沒(méi)作用.于是又照著指示輸入了第二個(gè)命令:root@username:~# journalctl -xe-- Subject: Session 12 has been terminated-- Defined-By: systemd-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel-- Documentation: http://www.freedesktop.org/wiki/Software/systemd/multiseat---- A session with the ID 12 has been terminated.Oct 23 08:33:44 username sshd[8792]: Connection closed by 120.92.72.31 [preauth]Oct 23 08:33:45 username sshd[8770]: pam_unix(sshd:session): session closed for user rootOct 23 08:33:45 username systemd-logind[551]: Removed session 13.-- Subject: Session 13 has been terminated-- Defined-By: systemd-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel-- Documentation: http://www.freedesktop.org/wiki/Software/systemd/multiseat---- A session with the ID 13 has been terminated.Oct 23 08:34:06 username sshd[8795]: Connection closed by 120.92.72.31 [preauth]Oct 23 08:34:54 username sshd[8797]: Connection closed by 106.187.100.177 [preauth]Oct 23 08:35:16 username sshd[8799]: Connection closed by 120.92.72.31 [preauth]Oct 23 08:35:35 username sshd[8801]: Connection closed by 120.92.72.31 [preauth]Oct 23 08:36:33 username sudo[8806]: root : TTY=pts/1 ; PWD=/etc/nginx/sites-available ; USER=Oct 23 08:36:33 username sudo[8806]: pam_unix(sudo:session): session opened for user root by root(Oct 23 08:36:33 username sudo[8806]: pam_unix(sudo:session): session closed for user rootOct 23 08:36:48 username sudo[8829]: root : TTY=pts/1 ; PWD=/etc/nginx/sites-available ; USER=Oct 23 08:36:48 username sudo[8829]: pam_unix(sudo:session): session opened for user root by root(Oct 23 08:36:48 username sudo[8829]: pam_unix(sudo:session): session closed for user rootOct 23 08:36:50 username sshd[8852]: Connection closed by 120.92.72.31 [preauth]Oct 23 08:37:25 username sshd[8854]: Connection closed by 120.92.72.31 [preauth]Oct 23 08:37:57 username sshd[8856]: Connection closed by 101.200.80.28 [preauth]Oct 23 08:38:03 username sshd[8858]: Connection closed by 120.92.72.31 [preauth]
換著關(guān)鍵詞關(guān)鍵句搜了好幾種,才搜出來(lái)一種答案比較多的.root@username:~# nginx -tnginx: [emerg] a duplicate default server for 0.0.0.0:80 in /etc/nginx/sites-enabled/default-backup: 17nginx: configuration file /etc/nginx/nginx.conf test failed
就兩句話,然后都了一下,眼睛瞪大--恍然大悟!nginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful
簡(jiǎn)單兩句,看著真給力.server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html; index index.html index.htm index.nginx-debian.html; server_name _; location / { try_files $uri $uri/ =404; }}
之前看過(guò)兩三集的nginx教程, 有那么一點(diǎn)點(diǎn)印象而已.新手學(xué)東西不能怕錯(cuò),但是不能少了猜.如果有人看到這里,也請(qǐng)不要嫌我業(yè)余.
listen 80 default_server; 好像是說(shuō)默認(rèn)服務(wù)器會(huì)監(jiān)聽(tīng)80端口.然后就可以開(kāi)始正式學(xué)習(xí)nginx語(yǔ)法了.
但listen [::]:80 default_server;就不知道了,看下一句.
root /var/www/html; 這個(gè)好理解,那就是網(wǎng)站(也叫站點(diǎn), 應(yīng)用, app等)的根目錄位置.
看到一些老視頻,好像過(guò)去nginx的默認(rèn)根目錄在/usr/share/html這里.
新nginx改到這里更好,和apache一樣,省得去記別的了.
server_name _; 這個(gè),估計(jì)是站點(diǎn)名字或者網(wǎng)址吧?
location / {...} 這可能定義根目錄的一些url地址問(wèn)題?
try_files $url $url/ =404, 這個(gè)還真有點(diǎn)不好猜,只知道估計(jì)是和404文件未找到有關(guān).
# Upstream 用來(lái)抽象化php的后端連接upstream php { server unix:/tmp/php-cgi.socket; server 127.0.0.1:9000;}server { ## 把你的網(wǎng)址放在這里,如baidu.com server_name baidu.com; ## 只此一處的站點(diǎn)根目錄地址的聲明 root /var/www/wordpress; ## 這句應(yīng)該寫(xiě)在http區(qū)塊(類(lèi)似http {...}這樣的)里, ## 如果你寫(xiě)了http區(qū)塊,就沒(méi)必要放在這. index index.php; ## (設(shè)置網(wǎng)站favicon.ico圖標(biāo)的訪問(wèn)邏輯,) location = /favicon.ico { # (如果沒(méi)找到這個(gè)文件,則不適用規(guī)則) log_not_found off; access_log off; } ## (設(shè)置robots.txt的訪問(wèn)邏輯) ## (允許所有對(duì)它的訪問(wèn)(因?yàn)槊總€(gè)訪問(wèn)者都應(yīng)該遵守嘛)) location = /robots.txt { allow all; # (如果沒(méi)找到這個(gè)文件,則不適用規(guī)則) log_not_found off; access_log off; } ## (根目錄的訪問(wèn)邏輯. 注:"/"代表根目錄) location / { # 這句話巨酷, 因?yàn)闆](méi)有php會(huì)被當(dāng)成靜態(tài)文件訪問(wèn) # 加入"?$args"這部分后, 非默認(rèn)的固定鏈接在使用url查詢字串時(shí)就不會(huì)中斷 try_files $uri $uri/ /index.php?$args; } ## (目錄中所有.php文件的訪問(wèn)邏輯) location ~ /.php$ { #注意: 你應(yīng)該在php.ini中寫(xiě)了"cgi.fix_pathinfo = 0;" 這句話. # (引入fastcgi.conf這個(gè)文件) include fastcgi.conf; # (fastcgi相關(guān)的報(bào)錯(cuò):開(kāi)) fastcgi_intercept_errors on; fastcgi_pass php; } ## (目錄中所有的js|css|png|jpg|jpeg|gif|ico文件訪問(wèn)邏輯) location ~* /.(js|css|png|jpg|jpeg|gif|ico)$ { ## 最大過(guò)期期限 expires max; ## 如果沒(méi)有找到這個(gè)文件 則不適用規(guī)則 log_not_found off; }}
上面的中文是我自己翻譯的, 帶括號(hào)的注釋中是我根據(jù)字面意思猜測(cè)的.location /wordpress { try_files $uri $uri/ /wordpress/index.php?$args;}location ~ /.php$ { fastcgi_split_path_info ^(/wordpress)(/.*)$;}
上面說(shuō)是,如果你想把wordpress作為一個(gè)子目錄(而不是網(wǎng)站的根目錄)使用,那你應(yīng)該在上面總配置中相應(yīng)位置加上這幾句代碼.map $uri $blogname{ ~^(?P<blogpath>/[^/]+/)files/(.*) $blogpath ;}map $blogname $blogid{ default -999; #Ref: http://wordpress.org/extend/plugins/nginx-helper/ #include /var/www/wordpress/wp-content/plugins/nginx-helper/map.conf ;}server { server_name example.com ; root /var/www/example.com/htdocs; index index.php; location ~ ^(/[^/]+/)?files/(.+) { try_files /wp-content/blogs.dir/$blogid/files/$2 /wp-includes/ms-files.php?file=$2 ; access_log off; log_not_found off; expires max; } #avoid php readfile() location ^~ /blogs.dir { internal; alias /var/www/example.com/htdocs/wp-content/blogs.dir ; access_log off; log_not_found off; expires max; } if (!-e $request_filename) { rewrite /wp-admin$ $scheme://$host$uri/ permanent; rewrite ^(/[^/]+)?(/wp-.*) $2 last; rewrite ^(/[^/]+)?(/.*/.php) $2 last; } location / { try_files $uri $uri/ /index.php?$args ; } location ~ /.php$ { try_files $uri =404; include fastcgi_params; fastcgi_pass php; } #add some rules for static content expiry-headers here}
這里官網(wǎng)的注釋解釋不多,而且很難字面上理解了, 所以先跳過(guò).# Upstream to abstract backend connection(s) for phpupstream up_php { server unix:/var/run/php5-fpm.sock; server 127.0.0.1:9000;}server { server_name _; root /var/www/html; index index.php; location = /favicon.ico { log_not_found off; access_log off; } location = /robots.txt { allow all; log_not_found off; access_log off; } location / { try_files $uri $uri/ /index.php?$args; } location ~ /.php$ { include fastcgi.conf; fastcgi_pass up_php; } location ~* /.(js|css|png|jpg|jpeg|gif|ico)$ { expires max; log_not_found off; }}
然后重啟nginx.噠噠噠!經(jīng)典的wordpress配置頁(yè)面出現(xiàn)啦!剩余步驟30秒內(nèi)全部完成!哈哈,太高興了.關(guān)鍵詞:服務(wù),學(xué)習(xí)
客戶&案例
營(yíng)銷(xiāo)資訊
關(guān)于我們
客戶&案例
營(yíng)銷(xiāo)資訊
關(guān)于我們
微信公眾號(hào)
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。