安装Nginx
apt-get install nginx
/etc/init.d/nginx stop
/etc/init.d/nginx start
定义下hosts就可以看结果啦
编辑/etc/hosts
或者
C:\Windows\System32\drivers\etc\hosts
加入
192.168.1.139 localhost139.com
然后打开浏览器就可以看结果
4.修改/ect/nginx/nginx.conf
server {
listen 80;
server_name localhost139.com;
charset utf-8;
access_log /home/localhost.log;
location /(css|js|fonts|img)/ {
access_log off;
expires 1d;
root "/path/to/app_a/static";
try_files $uri @backend;
}
location / {
try_files /_not_exists_ @backend;
}
location @backend {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:8080;
}
}
重启Nginx
/etc/init.d/nginx restart
负载均衡
轮询分配
upstream myupstream {
#ip_hash;
server 127.0.0.1:8080;
server 127.0.0.1:8081;
}
server {
listen 80;
server_name localhost139.com;
charset utf-8;
access_log /home/localhost.log;
location /(css|js|fonts|img)/ {
access_log off;
expires 1d;
root "/path/to/app_a/static";
try_files $uri @backend;
}
location / {
try_files /_not_exists_ @backend;
}
location @backend {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://myupstream;
}
}