運(yùn)行環(huán)境: centos7 php7.1 nginx 1.10 apache 2.4 php框架phalcon
nginx.conf配置
upstream lamp{
server 127.0.0.1:81 weight=1 max_fails=3 fail_timeout=30s;
}
server {
listen 80;
server_name we.test.com;
index index.php
root /wwwroot/test/public;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ .*\.(php|jsp|cgi)?$
{
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://lamp;
}
location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$
{
root /wwwroot/test/public;
expires 3d;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
apache vhost配置
<VirtualHost *:81>
ServerName we.test.com
DocumentRoot /wwwroot/test/public
<Directory wwwwroot/test/public>
Options FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
Require All granted
</Directory>
</VirtualHost>
.htaccess 文件 (在public目錄下)
AddDefaultCharset UTF-8
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>
當(dāng)我訪問(wèn) we.test.com:81的時(shí)候所有的路由可以正常訪問(wèn) 例如 we.test.com/user/login 或者 接受 參數(shù) we.test.com/article/index?id=5
但是當(dāng)我 訪問(wèn) nginx監(jiān)聽(tīng)的80端口 ,所有的訪問(wèn)都很奇怪,就是瀏覽器的url會(huì)變成對(duì)應(yīng)的路由 例如we.test.com/user/login 但是 頁(yè)面展示的內(nèi)容 還是 we.test.com的默認(rèn)頁(yè),只是刷新了一下。
剛剛嘗試這種 nginx 反向代理 apache ,不知道有沒(méi)有大神可以幫忙解答一下。非常非常感謝。 如有有缺少的條件,我會(huì)及時(shí)回復(fù) 在線等。。。
1 回答

回首憶惘然
TA貢獻(xiàn)1847條經(jīng)驗(yàn) 獲得超11個(gè)贊
apache不需要更改,nginx配置改一下
location / {
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?$1 last;
}
}
location ~ \.php$ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://lamp;
}
- 1 回答
- 0 關(guān)注
- 563 瀏覽
添加回答
舉報(bào)
0/150
提交
取消