加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 在同一台服务器上使用Nginx和Apache的潜在问题?

发布时间:2020-12-14 02:50:16 所属栏目:Linux 来源:网络整理
导读:我安装了nginx来处理与apache一起的请求.以前,apache在端口80上监听,我现在切换到nginx监听端口80和apache在一些不起眼的端口上,如果请求是非静态内容,则将nginx proxy_pass发送到apache. 我的nginx配置包含以下内容: server { listen 80; server_name stat
我安装了nginx来处理与apache一起的请求.以前,apache在端口80上监听,我现在切换到nginx监听端口80和apache在一些不起眼的端口上,如果请求是非静态内容,则将nginx proxy_pass发送到apache.

我的nginx配置包含以下内容:

server {
    listen 80;
    server_name static.test.domain.com;
    location / {
        root   /home/test/www/static;
        index  index.html index.htm;
    }

}

server {
    listen       80;
    server_name domain.com *.domain.com;
    location /
    {
        proxy_set_header Server "testserver";
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://localhost:8800;

    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

}

apache vhost配置具有以下内容:

NameVirtualHost *:8800

<VirtualHost *:8800>
  DocumentRoot /var/www/html
  ServerName domain.com
  ServerAlias www.domain.com
</VirtualHost>

<VirtualHost *:8800>
  DocumentRoot /home/test/www
  ServerName test.domain.com
</VirtualHost>

...

我注意到请求现在更快但我也注意到nginx出现在Server字段中的所有请求头中,即使请求是针对非静态页面的.这是一个潜在的问题吗?我见过一些服务器在同一个IP上使用nginx,比如我的设置,但是服务器字段不同(如果是非静态内容请求,则显示Apache,静态时显示nginx).

另外,我正在使用APC进行操作码缓存,并且我在我的站点目录中使用.htaccess和一些重定向规则(我想我需要将一些apache规则移植到nginx?这是必要的吗?).我还有一些运行的Java cron脚本(这会阻碍nginx进程吗?)这个新的设置会导致潜在的问题吗?

我知道很多问题.但提前谢谢!

更多信息:使用nginx 1.0.6与apache 2.2在Centos 5 32bit上运行.

我的.htaccess文件(其中一些需要移植到apache吗?):

# BEGIN Compress text files
<ifModule mod_deflate.c>
  <filesMatch ".(css|js|x?html?|php)$">
    SetOutputFilter DEFLATE
  </filesMatch>
</ifModule>
# END Compress text files


# BEGIN Expire headers
<ifModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 1 seconds"
  ExpiresByType image/x-icon "access plus 2592000 seconds"
  ExpiresByType image/jpeg "access plus 2592000 seconds"
  ExpiresByType image/png "access plus 2592000 seconds"
  ExpiresByType image/gif "access plus 2592000 seconds"
  ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
  ExpiresByType text/css "access plus 604800 seconds"
  ExpiresByType text/javascript "access plus 604800 seconds"
  ExpiresByType application/javascript "access plus 604800 seconds"
  ExpiresByType application/x-javascript "access plus 604800 seconds"
  ExpiresByType application/xhtml+xml "access plus 600 seconds"
</ifModule>
# END Expire headers


# BEGIN Cache-Control Headers
<ifModule mod_headers.c>
  <filesMatch ".(ico|jpe?g|png|gif|swf)$">
    Header set Cache-Control "max-age=2592000,public"
  </filesMatch>
  <filesMatch ".(css)$">
    Header set Cache-Control "max-age=604800,public"
  </filesMatch>
  <filesMatch ".(js)$">
    Header set Cache-Control "max-age=604800,private"
  </filesMatch>
</ifModule>
# END Cache-Control Headers


# BEGIN Turn ETags Off
<ifModule mod_headers.c>
  Header unset ETag
</ifModule>
FileETag None
# END Turn ETags Off

解决方法

考虑为Apache安装mod_rpaf,这将帮助您获取Apache访问日志中客户端的IP地址,而不是服务器的IP地址(技术上,nginx从Apache请求网页,因此Apache将其IP识别为不带mod_rpaf的客户端IP).这是我能想到的设置唯一可能出现的问题,其他一切看起来都是正确的.在每个标头中都有nginx是正确的,因为nginx作为每个网页的前端,包括静态和动态.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读