ラベル apache の投稿を表示しています。 すべての投稿を表示
ラベル apache の投稿を表示しています。 すべての投稿を表示

2024年6月30日日曜日

MPM preforkメモ

▪️デフォルト値のprefork 

<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    MaxRequestWorkers   256
    MaxConnectionsPerChild  0
</IfModule>


▪️vCPUが2048の場合

<IfModule mpm_prefork_module>
    StartServers          50
    MinSpareServers       50
    MaxSpareServers       100
    ServerLimit           2048
    MaxRequestWorkers     2048
    MaxConnectionsPerChild  0
</IfModule>


ApacheのMPM設定の確認

 apachectl -V | grep -i mpm


2024年6月20日木曜日

apache dump出力方法

FROM php:7.4-apache

## ダンプ設定 ###
RUN apt-get update && apt-get install -y \
gdb \
procps

# コアダンプの生成を有効化
RUN echo '* soft core unlimited' >> /etc/security/limits.conf && \
echo '* hard core unlimited' >> /etc/security/limits.conf

# ダンプファイルの出力先
RUN echo 'kernel.core_pattern=/tmp/core.%e.%p.%h.%t' > /etc/sysctl.d/99-custom.conf

# コアダンプを有効にするシェルスクリプトを追加
RUN echo 'ulimit -c unlimited' >> /etc/profile

2024年6月19日水曜日

apache abベンチマーク(https)のURLで実行する方法

 

ab -n 100 -c 100  -k -H "Accept-Encoding: gzip, deflate" https://www.test.com/


ここで使用しているオプションについて説明します:

  • -n 100: 総リクエスト数を100とします。必要に応じて変更してください。
  • -c 10: 同時に実行するリクエスト数を10とします。必要に応じて変更してください。
  • -k: Keep-Aliveを使用して接続を再利用します。これにより、同じ接続で複数のリクエストを行います。
  • -H "Accept-Encoding: gzip, deflate": HTTPヘッダーとしてAccept-Encodingを指定します。これは、サーバーからの圧縮されたレスポンスを受け取るための設定です。
  • https://example.com/: HTTPSプロトコルを使用してテストしたいサイトのURLを指定します。

apache チューニング


RUN sed -i '$a<IfModule mpm_prefork_module>' /etc/apache2/apache2.conf
RUN sed -i '$a StartServers 5' /etc/apache2/apache2.conf
RUN sed -i '$a MinSpareServers 5' /etc/apache2/apache2.conf
RUN sed -i '$a MaxSpareServers 10' /etc/apache2/apache2.conf
RUN sed -i '$a ServerLimit 100' /etc/apache2/apache2.conf
RUN sed -i '$a MaxClients 100' /etc/apache2/apache2.conf
RUN sed -i '$a MaxRequestsPerChild 80' /etc/apache2/apache2.conf
RUN sed -i '$a</IfModule>' /etc/apache2/apache2.conf

2024年6月16日日曜日

docker(php:7.4-apache)について

apacheとphpの連携は、 apacheモジュール(php7_module)を使うことで
HTTPリクエストに対してPHPを正しく処理できる状態にしている。

具体的には、php7_moduleがApacheのロードモジュールとしてリストされている場合、Apacheは.php拡張子を持つファイルを受け取った際に、そのファイルをPHPスクリプトとして解釈し、PHPエンジンを通じて処理することができます。

2024年5月22日水曜日

apache2 チューニング(for dockerfile)

参照先:
https://qiita.com/kaihei777/items/4e3c257e073eb886b38a

RUN sed -i 's/KeepAliveTimeout 5/KeepAliveTimeout 750/' /etc/apache2/apache2.conf
RUN sed -i 's/Timeout 300/Timeout 750/' /etc/apache2/apache2.conf

2024年5月20日月曜日

FROM php:7.4-apache(apacheのuser&groupの変更方法)

訳あって、FROM php:7.4-apacheでの実行ユーザーとグループの変更が必要になってので
以下の記載により再現させてみることに。


1)start-apache.shを作成

#!/bin/bash
# Apacheをapacheユーザーとして起動

# ログファイルの所有権を変更
chown apache:apache /var/log/apache2 /var/log/apache2/*

# Apacheをapacheユーザーとして起動
exec gosu apache /usr/sbin/apache2ctl -D FOREGROUND


2)dockerfileの作成を行う

FROM php:7.4-apache


# 新しいユーザー(test)とグループ(apache)を作成
RUN groupadd -r apache
RUN useradd -r -g apache test

# Apacheの環境変数のファイルを更新する(ユーザーとグループを変更)
RUN sed -i 's/APACHE_RUN_USER:=www-data/APACHE_RUN_USER:=test/g' /etc/apache2/envvars
RUN sed -i 's/APACHE_RUN_GROUP:=www-data/APACHE_RUN_GROUP:=apache/g' /etc/apache2/envvars

# apache log(所有者変更)
RUN chown test:apache -R /var/log/apache2
RUN chown test:apache -R /var/www/html
RUN chown test:apache -R /run/lock/apache2
RUN chown test:apache -R /run/apache2
RUN chown test:apache -R /var/cache/apache2/mod_cache_disk


# gosuのインストールに必要なパッケージのインストール
RUN apt-get update && apt-get install -y \  
wget \  
gnupg2 \  
dirmngr \  
&& rm -rf /var/lib/apt/lists/*

# gosuのインストール
RUN set -eux; \  
wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/1.12/gosu-amd64"; \
wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/1.12/gosu-amd64.asc"; \
export GNUPGHOME="$(mktemp -d)"; \  
gpg --keyserver keyserver.ubuntu.com --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \  
gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \  
rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \  
chmod +x /usr/local/bin/gosu; \  
gosu --version; \  
apt-get purge -y --auto-remove wget gnupg2 dirmngr

# スクリプトをコピーして実行権限を付与
COPY start-apache.sh /usr/local/bin/start-apache.sh
RUN chmod +x /usr/local/bin/start-apache.sh

CMD ["start-apache.sh"]

2024年5月16日木曜日

Redhat linuxのdockerfileイメージで、apacheを実行(apacheユーザで)できない件


以下に追記することで、解消できたので記載します。


1)php-fpm.conf

#add ##
listen = /run/php-fpm/www.sock


2)dockerfileに以下を記載。

# ApacheユーザーのUIDを1001に変更
RUN usermod -u 1001 apache && groupmod -g 1001 apache

# PHP-FPMユーザーのUIDを1001に変更(もし必要なら)
RUN usermod -u 1001 apache && groupmod -g 1001 apache

# ApacheとPHP-FPMのディレクトリの所有権を変更
RUN chown -R apache:apache /var/www && \
chown -R apache:apache /etc/httpd && \
chown -R apache:apache /var/log/httpd && \
chown -R apache:apache /var/run/httpd && \
chown -R apache:apache /var/log/php-fpm && \
mkdir -p /run/php-fpm && \
chown -R apache:apache /run/php-fpm

# ソケットファイルのディレクトリを作成し権限変更
RUN mkdir -p /run/php-fpm && chown -R apache:apache /run/php-fpm

2024年5月15日水曜日

Apache MPM Eventsの値

参照先:
https://qiita.com/rryu/items/5e02ea60e36d7fd956b8

以下、httpd.confに追記する。

<IfModule mpm_event_module>
StartServers 8
MinSpareThreads 50
MaxSpareThreads 175
ThreadLimit 64
ThreadsPerChild 25
MaxRequestWorkers 150
MaxConnectionsPerChild 10
</IfModule>


apacheの再起動して、プロセスの確認をしてみる










2024年5月13日月曜日

Apacheの特権分離について

 Apache HTTPサーバーが通常、rootユーザーで起動し、その後特権を降格してからリクエストを処理するメカニズムは、セキュリティと安全性を確保するための重要な設計です。これを理解するために、以下のポイントを詳しく解説します。

  1. 起動時の特権 Apache HTTPサーバーは通常、起動時にはrootユーザーとして実行されます。これにより、Apacheは必要なファイルやポートにアクセスするために必要な特権を持つことができます。

  2. 特権の降格(特権分離) Apacheが必要な初期設定やファイルへのアクセスを完了した後、特権を降格します。特権の降格はセキュリティ上の理由から行われます。root権限を持つプロセスは攻撃者によって悪用される可能性が高いため、リクエストを処理する段階では特権を持たない一般ユーザーとして動作することが推奨されます。

  3. セキュリティ向上 特権の降格により、Apacheは攻撃者が攻撃に使用できる潜在的な脆弱性を利用されにくくなります。例えば、特権を持つプロセスがリクエストを処理する場合、攻撃者はそのプロセスを標的にしようとします。しかし、特権を持たない一般ユーザーとして動作するApacheは、攻撃者にとっては難しいターゲットとなります。

  4. セキュリティ対策の重要性 特権の降格はセキュリティ対策の重要な要素の1つですが、それだけでなく他のセキュリティ対策も必要です。例えば、適切なファイルアクセス権限の設定、セキュリティパッチの適用、DoS攻撃への対策などがあります。

総じて、Apache HTTPサーバーがroot権限で起動してから特権を降格するメカニズムは、システム全体のセキュリティを向上させる重要な手段です。これにより、潜在的な攻撃からシステムを保護し、安全性を確保することが可能となります。

MPM prefork(Apache):チーニング編


 1)/etc/httpd/conf.d/mpm.confを作成する

<IfModule mpm_prefork_module>
StartServers 400
MinSpareServers 400
MaxSpareServers 400
ServerLimit 400
MaxClients 400
MaxRequestsPerChild 80
</IfModule>

2)00-mpm.confの編集を行う。

# Select the MPM module which should be used by uncommenting exactly
# one of the following LoadModule lines. See the httpd.conf(5) man
# page for more information on changing the MPM.

# prefork MPM: Implements a non-threaded, pre-forking web server
# See: http://httpd.apache.org/docs/2.4/mod/prefork.html
#
# NOTE: If enabling prefork, the httpd_graceful_shutdown SELinux
# boolean should be enabled, to allow graceful stop/shutdown.
#

## mpm_prefork ##
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so

# worker MPM: Multi-Processing Module implementing a hybrid
# multi-threaded multi-process web server
# See: http://httpd.apache.org/docs/2.4/mod/worker.html
#
#LoadModule mpm_worker_module modules/mod_mpm_worker.so

# event MPM: A variant of the worker MPM with the goal of consuming
# threads only for connections with active processing
# See: http://httpd.apache.org/docs/2.4/mod/event.html
#

## Default setting ##
#LoadModule mpm_event_module modules/mod_mpm_event.so


3)httpd.confに追記

KeepAlive On
MaxKeepAliveRequests 80
KeepAliveTimeout 120

4)apache のサービスを再起動






2024年5月8日水曜日

apache .htaccessのデバッグについて

dockerfileにapacheを入れているので、以下の記載により詳細なデバッグログが表示される 

RUN sed -i 's/LogLevel warn/LogLevel info rewrite:trace8/g' /etc/apache2/apache2.conf

2024年4月21日日曜日

PHP log設定(debug編)

 以下を追記

  ->logLevel は用途に応じて

httpd.conf

———

ErrorLog "logs/php/error.log"

LogLevel debug

————


php.ini

以下に編集する。

———————————

# エラーログを有効にする

log_errors = On


# エラー表示を有効にする(開発環境用)

display_errors = On


# エラーレポートのレベルを指定する(開発環境用)

error_reporting = E_ALL


# デバッグレベルのログを出力する

# 以下のように設定することで全てのログが出力される

log_errors_max_len = 0

————————————



apacheの再起動を行う



以下に出力される(ディレクトリの作成が必要)

mkdir -p /etc/httpd/logs/php/

2018年12月23日日曜日

Apache(SSL設定方法)


1)mod_sslをインストールする。
yum install mod_ssl


2)ssl.confの編集を行う。

=======/etc/httpd/conf.d/ssl.conf============
#
# When we also provide SSL we have to listen to the
# the HTTPS port in addition.
#
#Listen 443 https  <--無効化にする。
          .
          .
          .   

#   SSL Protocol support:
# List the enable protocol levels with which clients will be able to
# connect.  Disable SSLv2 access by default:
#SSLProtocol all -SSLv2 -SSLv3
SSLProtocol -all +TLSv1.2   <--追加する
          .
          .
          .
## 行の末端に新規追加 ##

<VirtualHost *:443>
  ErrorLog logs/ssl_error_log
  LogLevel warn
  SSLEngine on
  SSLProtocol all -SSLv3
  SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5
  SSLCertificateFile /etc/httpd/conf/server.crt    <--作成したserver.crtを指定すること
  SSLCertificateKeyFile /etc/httpd/conf/server.key <--作成したserver.keyを指定すること
  <Files ~ "\.(cgi|shtml|phtml|php3?)$">
        SSLOptions +StdEnvVars
    </Files>
    BrowserMatch "MSIE [2-5]" \
             nokeepalive ssl-unclean-shutdown \
             downgrade-1.0 force-response-1.0
    CustomLog logs/ssl_access_log ltsv_ssl
</VirtualHost>

========================================



3)httpd.confの編集を行う。

=======/etc/httpd/conf/httpd.conf===========
#Listen 12.34.56.78:80
#Listen 80
Listen 192.168.1.111:443  <----サーバのIP:443を追記する。


##### 末端に以下を追記 ######
Include /etc/httpd/conf.d/ssl.conf

<IfModule ssl_module>
 SSLRandomSeed startup builtin
 SSLRandomSeed connect builtin
</IfModule>

===========================================



4)httpdのサービスを再起動を行う
systemctl restart httpd


2017年11月24日金曜日

Apache2.4設定メモ(色々混み)

■Apache(2.4.6)
# yum -y install httpd


■PHP(7.1.6)
◻️レポジトリーの追加
# yum -y install epel-release
sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
◻️インストールを行う
# yum -y install --enablerepo=remi-php71 php php-cli php-common php-devel php-fpm php-gd php-mbstring php-mysqlnd php-pdo php-pear php-pecl-apcu php-soap php-xml php-xmlrpc

◆◇redisの設定については、別紙(redis編)を参照すること!!

[Apache(httpd.ini)編集]
◻️ServerTokens
ファイルの末尾に追記する。
ServerTokens ProductOnly


※末尾に記載しないとサービス再起動でエラーになるので注意が必要!!


◻️Server-Pool Size
[Apache2.4の場合、項目が存在しない]


以下、内容を追記する


----------ここから-----------
## Server-Pool Size Regulation (MPM specific) ##


<IfModule prefork.c>
StartServers       8
MinSpareServers    5
MaxSpareServers   20
ServerLimit      256
MaxClients       256
MaxRequestsPerChild  4000
</IfModule>
----------ここまで------------


◻️ServerName
以下を追記
localhost:80


◻️DocumentRoot
変更不要


◻️ドキュメントルートの設定
------ここから-----------------
<Directory "/var/www/html">
Options FollowSymLinks Includes
AllowOverride All
   Order allow,deny
   Allow from all
</Directory>
------ここまで-----------------

◻️"/var/www/html"の権限、所有者の変更を行う。


1)新規グループ作成
<参照先>
http://neoblog.itniti.net/memo-add-user-group-centos7


2)所有グループとグループIDを付与
# groupadd -g 5000 edit


3)ディレクトリ所有者の変更
# chown root html


4)ディレクトリのグループ名の変更
# chgrp edit html


5)パーミッションの変更
# chmod 775 html

◻️ログ設定
以下、コンフィグに内容を追記する。


LogFormat "%h %{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %D" combined
CustomLog logs/access_log combined env=!health_check
SetEnvIf User-Agent "Data-Hotel-Watchdog/1.1" health_check  
CustomLog logs/health_check_log combined env=health_check

◻️ServerSignature offの設定
※Apache 2.4の場合はdefaultでServerSignature Off

◻️AddDefaultCharset offの設定
以下のように"#"を追記するだけでよい。


#AddDefaultCharset UTF-8

◻️SSL設定
以下の内容に”.html .php”を追記する。


AddType text/html             .shtml .html .php
AddOutputFilter INCLUDES         .shtml .html .php

◻️エラードキュメント設定
以下を追記する。


ErrorDocument 403 /404.html
ErrorDocument 404 /404.html

◻️リバースプロキシ設定
<参照先>
http://qiita.com/gingi99/items/83c1fb07644cd232d91e


最終行などの空いているところに追記を行う
※記述方法ついては、本番環境導入前に検討が必要


ProxyRequests Off
ProxyPass /[要検討]/app/action/AJaccsReturnDownload http://localhost:8080/[要検討]/app/action/AJaccsReturnDownload timeout=300
ProxyPass /[要検討]/app/action/AJobCheck http://localhost:8080/[要検討]/app/action/AJobCheck timeout=60
ProxyPass /[要検討]/app/action/ALogCheck http://localhost:8080/[要検討]/app/action/ALogCheck timeout=300
ProxyPass /[要検討] http://localhost:8080/[要検討] timeout=20

◻️X-Frame-Options
以下を追記する。


Header always append X-Frame-Options "ALLOW-FROM http://[サイト名]"


■/etc/sysconfig/httpdの編集
以下、コマンドにて追記を行う


echo "umask 002" >> /etc/sysconfig/httpd

■/etc/logrotate.d/httpdの編集
以下の内容に差し替えること!


-----ここから------------------
/var/log/httpd/access_log
/var/log/httpd/error_log
/var/log/httpd/health_check_log
{
   daily
   rotate 30
   missingok
   notifempty
   sharedscripts
   delaycompress
   postrotate
       /bin/systemctl reload httpd.service > /dev/null 2>/dev/null || true
   endscript
}
-----ここまで------------------

■ベーシック認証(asoociation)
<参照先>
http://qiita.com/shell/items/5606d37a802e39479036


※設定方法は要相談

�@.htaccess作成
htpasswd -c -b /etc/httpd/conf/.htpasswd ユーザ名 パスワード


◻️httpd.confの修正


配下に、追記を行う
<Directory "/var/www/html">
AuthUserFile /etc/httpd/conf/.htpasswd


◻️サービスの再起動
# systemctl restart httpd

■/etc/php.iniの編集


expose_php         Off
error_reporting         E_ALL & ~E_NOTICE & ~E_DEPRECATED
date.timezone         Asia/Tokyo
session.use_only_cookies 0
session.use_trans_sid     1
session.gc_divisor     100
session.gc_maxlifetime     1800




ローカルLLMでコーディングさせるポイント

 簡単な指示で、依頼するとコンテキストオーバーで記憶喪失になって コードの内容が一致しないことが起こるので、work.mdみたいな作業メモを取らせたるのがよい 途中から、別スレッドに再実施する場合でも、work.mdが引き継ぎとして 参照して実施してくれるのがポイント