[toc]
Linux下安裝Nginx
-
下載nginx:http://nginx.org/en/download.html
image.png
-
安裝依賴包
yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel // 安裝過(guò)程中,要選擇:y yum install GeoIP gd libXpm libxslt // 安裝gcc gcc-c++ yum -y install gcc gcc-c++ autoconf automake make
-
安裝nginx
// 解壓 tar -zxvf nginx-1.14.0.tar.gz cd nginx-1.14.0/ // 安裝到/usr/local/nginx目錄下 ./configure --prefix=/usr/local/nginx make make install
nginx常用命令
- 啟動(dòng)命令:
/usr/local/nginx/sbin/nginx
- 重啟命令:
/usr/local/nginx/sbin/nginx -s reload
- 查看命令:
ps -ef | grep nginx
- 關(guān)閉命令:
kill -9 進(jìn)程號(hào)
nginx常用配置
配置文件位置:/usr/local/nginx/conf/nginx.conf
Nginx初試Tomcat不脯,部署Guns-admin
網(wǎng)上關(guān)于nginx的資料很零碎府怯,我就想整個(gè)tomcat+nginx運(yùn)行一下guns的項(xiàng)目而已,訪問(wèn)admin.idudiao.com后轉(zhuǎn)到服務(wù)器上的
http://localhost:8080/guns-admin
上防楷,無(wú)果牺丙,不是重定向次數(shù)過(guò)多,就是session失效复局。
最后赘被,用了個(gè)折中的法子是整,訪問(wèn)admin.idudiao.com后轉(zhuǎn)到服務(wù)器上的http://localhost:8080
-
部署guns-admin項(xiàng)目,同時(shí)修改項(xiàng)目發(fā)布路徑為:''民假。 修改tomcat/conf/server.xml
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <!-- SingleSignOn valve, share authentication between web applications Documentation at: /docs/config/valve.html --> <!-- <Valve className="org.apache.catalina.authenticator.SingleSignOn" /> --> <!--修改發(fā)布路徑--> <Context path="" docBase="/tomcat-8.0.53-guns/webapps/guns-admin" debug="0" reloadable="true"/> <!-- Access log processes all example. Documentation at: /docs/config/valve.html Note: The pattern used is equivalent to using pattern="common" --> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host>
參考:https://blog.csdn.net/u011042133/article/details/46349593
-
path
是虛擬路徑; -
docBase
是應(yīng)用程序的物理路徑龙优; -
debug
則是設(shè)定debug level, 0表示提供最少的信息羊异,9表示提供最多的信息; -
reloadable
如果為true彤断,則tomcat會(huì)自動(dòng)檢測(cè)應(yīng)用程序的/WEB-INF/lib 和/WEB-INF/classes目錄的變化野舶,自動(dòng)裝載新的應(yīng)用程序,可以在不重起
-
-
配置Nginx宰衙,修改
/usr/local/nginx/conf/nginx.conf
文件平道,在http{}模塊下添加:http { ... #add by dudiao at 20180815 server { listen 80; server_name admin.idudiao.com; location / { proxy_pass http://localhost:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location ~ .*\.(gif|jpg|jpeg|png|js|css)$ { root /tomcat-8.0.53-guns/webapps/guns-admin/; expires 1d; } } #add by dudiao end ... }