日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

nginx 入门配置

發(fā)布時(shí)間:2025/3/13 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 nginx 入门配置 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

這個(gè)星期公司的定期分享內(nèi)容是Nginx,于是就要寫作業(yè)了。

一、動(dòng)靜分離

1、下載Windows 版本的Nginx,解壓,放到C盤下。進(jìn)入目錄,然后按然shift鍵右鍵,打開(kāi)命令行,輸入:

start nginx

2、訪問(wèn)localhost,啟動(dòng)成功。

3、然后做如下配置:

4、啟動(dòng)tomcat,訪問(wèn)localhost:8080:

5、重啟nginx:

nginx -s reload

6、訪問(wèn)localhost/index.jsp,靜態(tài)文件全部找不到,頁(yè)面跑版。

7、把tomcat的靜態(tài)文件放到目錄下, 再次訪問(wèn)localhost/index.jsp:

8、一個(gè)簡(jiǎn)單的動(dòng)靜分享就做完啦。

?

二、綁定多個(gè)域名

1、在配置文件和server同級(jí)的位置加上這一句

include C:/nginx-1.9.1/conf/vhosts/*.conf;

2、在conf目錄下新建一個(gè)vhosts文件夾,里面新建兩個(gè)文件:

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.com

4、重啟nginx

nginx -s reload

5、分別訪問(wèn)star.ice.com和tomcat.ice.com:

6、打完收工,關(guān)閉nginx:

nginx -s quit

?

三、負(fù)載均衡

1、搭三個(gè)服務(wù)器:

192.168.1.104;
127.0.0.1:8080;
192.168.188.132:8080;

2、配置nginx.conf, 沒(méi)有用的已經(jīng)省略掉了(這里可以配置各種策略,具體參考官方文檔吧):

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、重新啟動(dòng)nginx:

nginx -s reload

4,往host文件中加入

127.0.0.1 www.ice.com

5、打開(kāi)www.ice.com,可以刷出以下三個(gè)頁(yè)面:

6、負(fù)載均衡的最基本配置也做完啦。。。

轉(zhuǎn)載于:https://www.cnblogs.com/yingbing/p/4555267.html

總結(jié)

以上是生活随笔為你收集整理的nginx 入门配置的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。