サーバ
APサーバ Servlet/JSPコンテナ
Jetty
Resin
Webサーバ
Apache
sudo apt-get install apache2
sudo service apache2 status
Tomcat
>Ubuntuの場合
sudo apt-get install tomcat6
sudo service tomcat6 status
設定ファイル:/etc/default/tomcat6
JAVA_HOME=/usr/lib/jvm/java-7-oracle
JAVA_OPTS="-Dcom.sun.management.jmxremote -Djava.awt.headless=true -Xms1024M -Xmx1024M -XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=512m -XX:MaxPermSize=512m -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC"
>Windowsの場合
JSPファイルパス
<%TOMCAT_HOME%>\webapps\Sample\WEB-INF\jsp
JSPファイルから変換されるJavaファイルのパス
<%TOMCAT_HOME%>\work\Catalina\localhost\Sample\org\apache\jsp
★JNDIの設定
方法1:server.xml 再起動は必要
方法2:context.xml 再起動は不要
MySQLサンプル
<Resource
name="jdbc/mysql"
auth="Container"
type="javax.sql.DataSource"
maxActive="100" 最大コネクション
maxIdle="30"
maxWait="60"
wait_timeout="18800"
timeBetweenEvictionRunsMillis="300000"
minEvictableIdleTimeMillis="600000"
username="root"
password="1234"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/mydb"
removeAbandoned="true"
removeAbandonedTimeout="60"
logAbandoned="true"/>
Oracleサンプル
<Resource
name="jdbc/oracle"
type="javax.sql.DataSource"
auth="Container"
username="root"
password="1234"
driverClassName="oracle.jdbc.driver.OracleDriver"
maxActive="100"
maxIdle="30"
maxWait="60"
url="jdbc:oracle:thin:@localhost:1521:mydb"
autoReconnect="true"/>
hibernate.cfg.xmlの場合
<property name="connection.datasource">java:/comp/env/jdbc/mysql</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
Java側
String env = "java:comp/env/";
Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup(env + "jdbc/mysql");
Connection conn = ds.getConnection();
JavaEEサーバ EJBコンテナ
GlassFish (Sun/Oracle)
glassfishv3\bin\asadmin start-domain
glassfishv3\bin\asadmin stop-domain
glassfish の管理コンソール
http://localhost:4848
GlassFish Eclipseプラグイン導入
[ヘルプ]→[Eclipseマーケットプレイス]を選択。
[glassfish]と入力し検索、[インストール]ボタンを選択。
MySQL連携
glassfishv3\glassfish\libに
mysql-connector-java-5.1.18.jarを入れる
サーバログ
glassfishv3\glassfish\domains\domain1\logs
データベース設定
Step 1 (Connection Pool)
Step 2 (Connection Pool)
※必須項目:serverName、portNumber、databaseName
オプション:user、password
Step 3 (JDBC Resources)
★簡単にサーバー構築
$ npm install -g http-server
$ http-server
★CUIツール
yum install httpd
# /etc/init.d/httpd <引数>
引数:start|stop|restart|condrestart|reload|status|fullstatus|graceful|configtest
使用中のプロセスが終了するのを待って再起動 /etc/init.d/httpd graceful
使用中のプロセスが終了するのを待って停止 /usr/sbin/apachectl graceful-stop
設定ファイルの構文誤りをテスト /etc/init.d/httpd configtest
使用できるポート番号の確認 /usr/sbin/semanage port -l
使用したいポート番号の追加 /usr/sbin/semanage port -a -t http_port_t -p tcp 9999
/usr/sbin/httpd -M モジュールの確認
/usr/sbin/httpd -l 静的モジュールの確認
★GUIツール
# yum install system-config-httpd
$ /usr/bin/system-config-httpd
デスクトップ:システム→管理→サーバー設定→HTTP
★設定ファイル /etc/httpd/conf/httpd.conf
※編集内容を反映するため:/etc/init.d/httpd reload
〇Timeout(単位:秒)
Timeout 60
〇Keep Alive(単位:秒)
※推薦 静的サーバ:on、動的サーバ:off
KeepAlive on
MaxKeepAliveRequests 200
KeepAliveTimeout 5
〇サーバ名
ServerName localhost:80
〇ポート番号
Listen 8080
〇連絡先メールアドレス
ServerAdmin postmaster@localhost
〇接続クライアント数
<IfModule prefork.c>
...
ServerLimit 300
MaxClients 300
...
</IfModule>
〇サーバの基点ディレクトリ
ServerRoot "C:/xampp/apache"
〇ドキュメントルート
DocumentRoot "C:/xampp/htdocs"
※http://localhost/doc/a.html と C:/xampp/htdocs/doc/a.html 対応
〇エイリアス
Alias /doc/ "D:/doc/"
<Directory "D:/doc">
Allow from all
</Directory>
※http://localhost/doc/a.html と D:/doc/a.html 対応
〇ディレクトリインデックス
DirectoryIndex index.html index.htm index.php
〇設定ファイルの取込
Include "conf/extra/httpd-xampp.conf"
〇MIMEタイプの追加
TypesConfig "conf/mime.types"
AddType application/x-httpd-php .php
〇キャッシュ
HTTP/1.0 Expires(絶対時間、GMT)
HTTP/1.1 Cache-Control: max-age(相対時間、単位は秒)
<IfModule expires_module>
ExpiresActive On
ExpiresByType application/x-javascript "access plus 30 days" アクセス時間により
#ExpiresByType application/x-javascript "modification plus 30 days" 更新時間により
ExpiresByType text/css "access plus 30 days"
ExpiresByType image/gif "access plus 30 days"
ExpiresByType image/jpeg "access plus 30 days"
ExpiresByType image/png "access plus 30 days"
</IfModule>
〇圧縮
<IfModule deflate_module>
AddOutputFilterByType DEFLATE application/x-javascript text/html text/plain text/xml text/css
</IfModule>
〇Last-ModifiedとETag
Last-Modified:リソースの更新時間
ETag:計算された文字列(計算処理があるため、無効にしよう)
FileETag None
Header unsets ETag
〇アクセス制限
アクセス制限の記述(Order, Allow, Deny)
リンク制限(SetEnvIf, Referer)
ベーシック認証・ダイジェスト認証を設定(AuthType)
★Apacheサーバの管理
動作状況の確認 http://localhost/server-status
設定情報の確認 http://localhost/server-info
Nginx
インストール
yum install gcc-c++
yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel
wget http://nginx.org/download/nginx-x.x.x.tar.gz
tar -zxv -f nginx-x.x.x.tar.gz
mv nginx-x.x.x nginx
cd /usr/local/nginx
./configure --prefix=/usr/local/nginx
make
make install
起動
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
/usr/local/nginx/sbin/nginx -s reload 再起動
停止
ps -ef | grep nginx
kill -quit <プロセスID>
kill -term <プロセスID>
pkill -9 nginx
確認
netstat na | grep 80
http://localhost:80