How to put multiple websites on a localhost port 80 using nginx.conf file? -
i used nginx setup virtual server , have nginx.conf
file below, works fine 2 different websites on http://localhost
, http://localhost:100
:
user nobody; worker_processes 1; error_log /usr/local/cellar/nginx/1.4.6/logs/error.log; pid /usr/local/cellar/nginx/1.4.6/logs/nginx.pid; events { worker_connections 1024; } http { include /usr/local/etc/nginx/mime.types; include /usr/local/etc/nginx/fastcgi.conf; default_type application/octet-stream; access_log /usr/local/var/log/nginx/access.log; sendfile on; tcp_nopush on; keepalive_timeout 65; gzip on; server { listen 80; server_name localhost; access_log /usr/local/cellar/nginx/1.4.6/logs/localhost.access.log combined; location / { root /users/apiah/websites/greenapple; index index.html index.htm index.php; } location ~ \.php$ { root /users/apiah/websites/greenapple; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param script_filename /users/apiah/websites/greenapple$fastcgi_script_name; include /usr/local/etc/nginx/fastcgi_params; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } server { listen 100; server_name localhost; access_log /usr/local/cellar/nginx/1.4.6/logs/localhost.access.log combined; location / { root /users/apiah/websites/blueweb; index index.html index.htm index.php; } location ~ \.php$ { root /users/apiah/websites/blueweb; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param script_filename /users/apiah/websites/blueweb$fastcgi_script_name; include /usr/local/etc/nginx/fastcgi_params; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
i test above 2 (or more) websites on same port 80 http://localhost
. example, assume have 3 folders called blueweb
, redweb
, greenweb
, want able see 3 folders when go http://localhost
, there choose go http://localhost/blueweb
, http://localhost/redweb
or http://localhost/greenweb
. please review nginx.conf
file , give me comments?
what want use subfolders instead of domain self, it's easy configure there's problem in cases, uri prepended website name.
so if using static html
pages or direct php
files fine, if using framework , framework using uri routing there problems because routes not match.
for example if visit http://localhost/redweb/homepage
uri /redweb/homepage
actual uri website should seeing /homepage
, fix need create rewrite each website.
you can try , if doesn't work tell me , i'll try you.
server { listen 80; server_name localhost; root /my/web/root; index index.html index.php; location / { try_files $uri $uri/; } }
Comments
Post a Comment