说明:示例中域名使用: www.test.com 项目使用: cms ,实际操作中自行替换
1、进行域名解析。将域名解析到对应的IP上。
2、将项目部署到tomcat中,端口采用默认的8080。启动tomcat,尝试使用域名+端口访问项目: www.test.com:8080/cms
如果能够正常访问,代表tomcat运行正常
3、安装nginx,如果是centos系统可以直接使用yum 安装
4、修改nginx的 nginx.conf文件,如果不知道文件路径,可以使用 find / -name nginx.conf 查找
文件内的配置如下:
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location = / {
#index test.html;
proxy_pass http://ip:8080/cms/index.html;
}
location ^~ / {
#index test.html;
proxy_pass http://ip:8080/cms/;
}
location ^~ /admin {
rewrite ^ http://ip:8080/cms/admin last;
}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}