nginx 入门配置
這個星期公司的定期分享內容是Nginx,于是就要寫作業了。
一、動靜分離
1、下載Windows 版本的Nginx,解壓,放到C盤下。進入目錄,然后按然shift鍵右鍵,打開命令行,輸入:
start nginx2、訪問localhost,啟動成功。
3、然后做如下配置:
4、啟動tomcat,訪問localhost:8080:
5、重啟nginx:
nginx -s reload6、訪問localhost/index.jsp,靜態文件全部找不到,頁面跑版。
7、把tomcat的靜態文件放到目錄下, 再次訪問localhost/index.jsp:
8、一個簡單的動靜分享就做完啦。
?
二、綁定多個域名
1、在配置文件和server同級的位置加上這一句
include C:/nginx-1.9.1/conf/vhosts/*.conf;2、在conf目錄下新建一個vhosts文件夾,里面新建兩個文件:
tomcat.conf
server {listen 80;server_name tomcat.ice.com;#charset koi8-r;#access_log logs/host.access.log main;location / {proxy_pass http://localhost:8080;}#error_page 404 /404.html;# redirect server error pages to the static page /50x.html#error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {# proxy_pass http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {# root html;# fastcgi_pass 127.0.0.1:9000;# fastcgi_index index.php;# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;# include fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {# deny all;#}}star.conf
server {listen 80;server_name star.ice.com;#charset koi8-r;#access_log logs/host.access.log main;location / {root "H:/repository/svn/4";index index.html index.htm;}#error_page 404 /404.html;# redirect server error pages to the static page /50x.html#error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {# proxy_pass http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {# root html;# fastcgi_pass 127.0.0.1:9000;# fastcgi_index index.php;# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;# include fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {# deny all;#}}3、在host文件中加下以下代碼:
127.0.0.1 star.ice.com 127.0.0.1 tomcat.ice.com4、重啟nginx
nginx -s reload5、分別訪問star.ice.com和tomcat.ice.com:
6、打完收工,關閉nginx:
nginx -s quit?
三、負載均衡
1、搭三個服務器:
192.168.1.104;
127.0.0.1:8080;
192.168.188.132:8080;
2、配置nginx.conf, 沒有用的已經省略掉了(這里可以配置各種策略,具體參考官方文檔吧):
http {upstream www.ice.com {server 192.168.1.104;server 127.0.0.1:8080;server 192.168.188.132:8080;}server{listen 80;server_name www.ice.com;location / {proxy_pass http://www.ice.com;proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }}}3、重新啟動nginx:
nginx -s reload4,往host文件中加入
127.0.0.1 www.ice.com5、打開www.ice.com,可以刷出以下三個頁面:
6、負載均衡的最基本配置也做完啦。。。
轉載于:https://www.cnblogs.com/yingbing/p/4555267.html
總結
以上是生活随笔為你收集整理的nginx 入门配置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MFC UI按钮多线程
- 下一篇: 敏捷开发过程中总结