项目部署到服务器 - wtdig/study GitHub Wiki

一、域名的解析

1、打开域名解析的网站,添加A记录2条,

2、其中一条为:记录类型为A,主机类型为@,解析路径为默认,记录值为服务器的ip地址;

3、另一台为:记录类型为A,主机类型为www,解析路径为默认,记录值为服务器的ip地址。

4、设置完之后,部署到该服务器上的项目,就可以指向绑定的域名了:比如我的域名:www.wtdig.top,访问该域名就可以指定到服务器地址;

二、通过域名访问,省略项目名的输入,

1、直接通过域名访问,无需输入项目名称,比如我的项目名称为wtdigssm;没有设置之前,通过www.wtdig.top/wtdigssm访问;

设置之后通过www.wtdig.top访问;

2、修改tomcat中的conf中的server.xml,在<host></host>标签里面,添加

<Context docBase="/usr/tomcat/apache-tomcat-7.0.57/webapps/wtdigssm" path="" reloadable="false"/>

其中docBase为tomcat中部署的项目位置

三、nginx配置文件实例


user  root;
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;
	#负载均衡 其中mynginx的名称与反向代理location proxy_pass名字一样
    upstream mynginx{
	    server 192.168.0.6:8080;
    }

    server {
        listen       9098;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
		#当被拦截时,会自己去找root路径下的资源
		root /wttemp/tomcat/apache-tomcat-7.0.57/webapps/ROOT;
	
		#拦截静态资源,实现动静分离
		location ~* .*\.(html|htm|js|css)$ {
           
        }

		location ~* .*\.(jpg|jpeg|gif|png|swf|ico)$ {
            
        }
		#反向代理
        location / {
            proxy_pass http://mynginx;
        }

        #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;
        #}
    }


    # 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;
    #    }
    #}

}

⚠️ **GitHub.com Fallback** ⚠️