nginx设置动静分离
程序员文章站
2022-05-22 09:05:33
...
nginx配置动静分离
安装jdk
rpm -ivh jdk-7u79-linux-x64.rpm
设置jdk环境变量
vim /etc/profile
JAVA_HOME="/usr/java/jdk1.7.0_79"
CLASS_PATH="$JAVA_HOME/lib:$JAVA_HOME/jre/lib"
PATH=".:$PATH:$JAVA_HOME/bin "
CATALINA_HOME="/usr/local/tomcat"
export JAVA_HOME CATALINA_HOME
安装tomcat
tar xvf apache-tomcat-7.0.64.tar.gz -C /usr/local/
cd apache-tomcat-7.0.64.tar.gz
ln -s apache-tomcat-7.0.64 tomcat
修改日志
vim /usr/local/tomcat/conf/server.xml
修改日志如下
prefix="localhost_access_log." suffix=".txt"
pattern="%{x-forwarded-for}i %l %u %t "%r" %s %b" />
启动tomcat
cd /usr/local/tomcat/bin/; ./shutdown.sh
;./startup.sh
nginx 安装
tar xvf nginx-1.4.7.tar cd
nginx-1.4.7.gz -C /usr/local/
需要先安装pcre
./configure --prefix=/usr/local/nginx --with-http_gzip_static_module --with-http_stub_status_module --with-pcre=/root/pcre-8.37
建立nginx账号
useradd nginx -s /sbin/nologin
cd /usr/local/nginx;
mkdir vhosts.d
touch proxy.conf写入
#!nginx (-)
# proxy.conf
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; #获取真实ip
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #获取代理者的
真实ip
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
动静分离配置,jsp交给tomat处理,静态交给nginx处理
touch vhosts.d/daeom.conf
upstream webserver{
server localhost:8080;
# server localhost:80;
}
server {
listen 80;
server_name localhost;
root /data/www/web; #目录777,文件644 权限
index index.shtml index.html index.htm;#必须写全,要不然会出现403错误
location / {
root /data/www/web;
index index.shtml index.html index.htm;
proxy_set_header X-Real-IP $remote_addr;
include /usr/local/nginx/conf/proxy.conf;
}
location ~ .*.jsp$ #所有jsp的页面均交由tomcat处理
{
index index.jsp;
proxy_pass http://localhost:8080;#转向tomcat处理
include /usr/local/nginx/conf/proxy.conf;
# proxy_set_header X-Real-IP $remote_addr;
}
}
安装jdk
rpm -ivh jdk-7u79-linux-x64.rpm
设置jdk环境变量
vim /etc/profile
JAVA_HOME="/usr/java/jdk1.7.0_79"
CLASS_PATH="$JAVA_HOME/lib:$JAVA_HOME/jre/lib"
PATH=".:$PATH:$JAVA_HOME/bin "
CATALINA_HOME="/usr/local/tomcat"
export JAVA_HOME CATALINA_HOME
安装tomcat
tar xvf apache-tomcat-7.0.64.tar.gz -C /usr/local/
cd apache-tomcat-7.0.64.tar.gz
ln -s apache-tomcat-7.0.64 tomcat
修改日志
vim /usr/local/tomcat/conf/server.xml
修改日志如下
prefix="localhost_access_log." suffix=".txt"
pattern="%{x-forwarded-for}i %l %u %t "%r" %s %b" />
启动tomcat
cd /usr/local/tomcat/bin/; ./shutdown.sh
;./startup.sh
nginx 安装
tar xvf nginx-1.4.7.tar cd
nginx-1.4.7.gz -C /usr/local/
需要先安装pcre
./configure --prefix=/usr/local/nginx --with-http_gzip_static_module --with-http_stub_status_module --with-pcre=/root/pcre-8.37
建立nginx账号
useradd nginx -s /sbin/nologin
cd /usr/local/nginx;
mkdir vhosts.d
touch proxy.conf写入
#!nginx (-)
# proxy.conf
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; #获取真实ip
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #获取代理者的
真实ip
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
动静分离配置,jsp交给tomat处理,静态交给nginx处理
touch vhosts.d/daeom.conf
upstream webserver{
server localhost:8080;
# server localhost:80;
}
server {
listen 80;
server_name localhost;
root /data/www/web; #目录777,文件644 权限
index index.shtml index.html index.htm;#必须写全,要不然会出现403错误
location / {
root /data/www/web;
index index.shtml index.html index.htm;
proxy_set_header X-Real-IP $remote_addr;
include /usr/local/nginx/conf/proxy.conf;
}
location ~ .*.jsp$ #所有jsp的页面均交由tomcat处理
{
index index.jsp;
proxy_pass http://localhost:8080;#转向tomcat处理
include /usr/local/nginx/conf/proxy.conf;
# proxy_set_header X-Real-IP $remote_addr;
}
}
以上就介绍了nginx设置动静分离,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。