「Linux/nginx/apache経由」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→動的処理はapacheに渡し、静的ファイルはapacheに渡さない場合の設定) |
(→mod_rpafのインストール) |
||
| 行43: | 行43: | ||
・・略・・ | ・・略・・ | ||
| − | == | + | ==apache側で、nginxからのクライアントipを受ける方法== |
| − | + | ===mod_remoteipをインストール=== | |
| − | + | <pre> | |
| − | + | # mod_remoteipのインストール確認 | |
| − | + | $ httpd -M 2>/dev/null | grep remoteip | |
| − | + | > remoteip_module (shared) # となればインストールされてる | |
| − | + | </pre> | |
| − | + | /etc/httpd/conf/httpd.confの下の方に以下追加 | |
| − | + | <pre> | |
| − | + | LoadModule remoteip_module modules/mod_remoteip.so | |
| − | + | ||
| − | + | <IfModule remoteip_module> | |
| − | + | RemoteIPHeader X-Forwarded-For | |
| + | RemoteIPInternalProxy 160.16.200.243 | ||
| + | LogFormat "%a %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined | ||
| + | LogFormat "%a %l %u %t \"%r\" %>s %b" common | ||
| + | </IfModule> | ||
| + | </pre> | ||
| + | |||
| + | apache再起動 | ||
| + | service httpd restart | ||
2025年7月26日 (土) 02:17時点における版
目次
apacheに引き渡す際のreverse_proxy設定
apacheでなく別のnginxに引き渡したい時も同様に使える(cookieもひき注がれる)
- /etc/nginx/conf.d/example.conf
server {
listen 8090;
server_name example.localhost;
location / {
proxy_pass http://127.0.0.1:80;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
動的処理はapacheに渡し、静的ファイルはapacheに渡さない場合の設定
server {
listen 8090;
server_name example.localhost;
location ~* \.(jpg|jpeg|gif|png|swf|css|js|inc|ico|pdf|flv|gz|woff|html|htm|txt|xml)$ {
root /var/www/zend/example/public;
index index.html;
ssi on;
access_log off;
break;
}
location / {
・・略・・
正規表現の最後に$が付いているが.png?v=20150101などの画像でもhitする
apache側port変更設定
- /etc/httpd/conf/httpd.conf
Listen 80 Listen 8080 NameVirtualHost *:80 NameVirtualHost *:8080
- /etc/httpd/conf/extra/example.conf
<VirtualHost *:8080> ・・略・・
apache側で、nginxからのクライアントipを受ける方法
mod_remoteipをインストール
# mod_remoteipのインストール確認 $ httpd -M 2>/dev/null | grep remoteip > remoteip_module (shared) # となればインストールされてる
/etc/httpd/conf/httpd.confの下の方に以下追加
LoadModule remoteip_module modules/mod_remoteip.so
<IfModule remoteip_module>
RemoteIPHeader X-Forwarded-For
RemoteIPInternalProxy 160.16.200.243
LogFormat "%a %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%a %l %u %t \"%r\" %>s %b" common
</IfModule>
apache再起動
service httpd restart
