nginx 反向代理
比方说我启动了一个web服务器192.168.1.51:8080,那我如何通过虚拟机(192.168.1.177)中的nginx代理这个web服务器呢
server { listen 80; #listen [::]:80; server_name www.blog.com; index index.html index.htm index.php default.html default.htm default.php; #root /home/wwwroot/www.blog.com; include none.conf; #error_page 404 /404.html; include enable-php.conf; location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { proxy_pass http://192.168.1.51:8080; # 图片代理 expires 30d; } location ~ .*\.(js|css)?$ { proxy_pass http://192.168.1.51:8080; # js/css 代理 expires 12h; } location ~ /\. { deny all; } location / { proxy_pass http://192.168.1.51:8080; #Proxy Settings proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } access_log off; }
红色部分是需要另行添加的。重启nginx 即可。