對應(yīng)的nginx配置如下:
80端口的配置: 訪問test.com/news => 127.0.0.1:8081 ,這里有一個(gè)需要注意的地方是轉(zhuǎn)發(fā)的url最后需要加上’/’,這相當(dāng)指定了url’/’,如果代理服務(wù)器地址中是帶有URL的,此URL會(huì)替換掉 location 所匹配的URL部分。
test.com/news/api,訪問的是ip:8081/api;而如果代理服務(wù)器地址中是不帶有URI的,則會(huì)用完整的請求URL來轉(zhuǎn)發(fā)到代理服務(wù)器test.com/news/api,訪問的是ip:8081/news/api。
server {
listen 80;
# listen [::]:80 default_server;
server_name test.com
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
location /news{
proxy_pass http:test.com:8081/;
}
}
8081端口的配置: 與平時(shí)配置沒什么差別
server {
listen 8081;
server_name localhost;
root /var/www/project;
location / {
index index.php index.html index.htm;
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/ngixn/html;
#}
#我部署的是PHP項(xiàng)目,這里配置PHP解析
location ~ \\\\.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
include /etc/nginx/fastcgi.conf;
}
}
更多關(guān)于云服務(wù)器,域名注冊,虛擬主機(jī)的問題,請?jiān)L問西部數(shù)碼官網(wǎng):m.ps-sw.cn