Reputation: 95
Now, I have two projects(sites) based on Laravel + PHP + MySQL + Nginx, vistors can access them by typing:
http://www.mysite.com:80 http://www.mysite.com:8001
Can I change the accessing method to virtual folder not by port?
http://www.mysite.com/project1 http://www.mysite.com/project2
The nginx conf files are (at /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
server { listen *:80; server_name www.mysite.com; server_tokens off; root /var/www/html/project2/public; client_max_body_size 100m; access_log /var/log/nginx/project2_access.log; error_log /var/log/nginx/project2_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; }
Upvotes: 2
Views: 650
Reputation: 3071
Sure - an example config will look like this:
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;
....
}
}
Upvotes: 0
Reputation: 1031
The only decent way to do it is by folder and virtual host rather than port.
Upvotes: 0