现在,我有两个基于Laravel + PHP + MySQL + Nginx的项目(站点),游客可以通过键入来访问它们:
http://www.mysite.com:80 http://www.mysite.com:8001
我可以不通过端口将访问方法更改为虚拟文件夹吗?
http://www.mysite.com/project1 http://www.mysite.com/project2
nginx conf文件是(在/etc/nginx/conf.d /):
project1.conf
server { listen *:80; server_name mysite.com www.mysite.com; server_tokens off; root /var/www/html/project1/public; client_max_body_size 100m; access_log /var/log/nginx/project1_access.log; error_log /var/log/nginx/project1_error.log; location / { index index.php index.html;}if (!-f $request_filename){ rewrite (.*) /index.php; } } location ~ \.php$ { include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; }
project2.conf
location / {
index index.php index.html;
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
答案 0 :(得分:0)
唯一可行的方法是使用文件夹和虚拟主机而不是端口。
答案 1 :(得分:0)
确定-示例配置如下:
server {
listen 8080;
root /var/www/html/project1/public;
......
}
server {
listen 8081;
root /var/www/html/project2/public;
......
}
server {
listen 80;
server_name mysite.com www.mysite.com;
.....
location /project1 {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
.....
}
location /project2 {
proxy_pass http://localhost:8081;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
....
}
}