主要是将nginx和apache配合起来使用.

使用nginx做反向代理将http请求返回给apache,使用apache来完成相关http请求服务,在多台服务器集群中使用比较实用。

使用nginx监听80端口,apache监听8080端口

 

安装配置nginx

第一步,安装并配置Nginx,安装完之后,配置文件都在/etc/nginx目录下,主设置文件/etc/nginx/nginx.conf,

1.更改/etc/nginx/nginx.conf

 server {
        listen      80;
        server_name  _;
        root        /var/www/linuxidc;
       
        location ~* .*\.(gif|jpg|jpeg|png|bmp|ico|css|js|txt|flv|swf|mid|doc|ppt|xls|pdf|txt|mp3|wma)$ {
            expires 2d;
        }
        # 如果你需要客户端缓存的内容以及媒体,图片等文件固定放置一些目录下的话,就把上面那个
        # location注释掉,用下面这种方式
        # location ~ ^/(images|javascript|js|css|flash|media|static)/  {
        #  expires 2d;
        #}
          
        location ~ .*\.(php?|cgi|pl|py)$ {
            proxy_pass http://127.0.0.1:8080; #这里更改为你的ip地址,没有就localhost
        }
        location ~ /\.ht {
            deny  all;
        }
        location ~ /.+\.(inc|conf|cnf) {
            deny  all;
        }
        access_log  /var/log/nginx/linuxidc-access.log main;
        #access_log off
    }

2.主要坑点在这里,需要修改/etc/nginx/proxy.conf的内容,(原先应该是空文件)添加以下内容:

proxy_redirect          off;
proxy_hide_header      Vary;
proxy_set_header        Accept-Encoding '';
proxy_set_header        Host            $host;
proxy_set_header        X-Real-IP      $remote_addr;
proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size    10m;
client_body_buffer_size 128k;
proxy_connect_timeout  90;
proxy_send_timeout      90;
proxy_read_timeout      90;
proxy_buffer_size      4k;
proxy_buffers          32 4k;
proxy_busy_buffers_size 64k;

3.关于location的更多用法可以参考博客:https://www.cnblogs.com/sign-ptk/p/6723048.html

 

安装配置apache

1.yum -y install httpd即可

2.安装apache扩展

yum -y install httpd-manual mod_ssl mod_perl mod_auth_mysql

3.默认/var/www/html目录存放网页文件,即输入ip后访问到的根目录

4.默认/etc/http/conf/http.conf为apache配置文件:

   其中Listen设置监听端口为8080(默认80)

    这里可以对apache进行一系列配置

5.Apache相关命令 

启动:systemctl start httpd 
重启:systemctl restart httpd 
停止:systemctl stop httpd 

配置到这里打开浏览器输入ip或者localhost就能看到如下画面

(一)CentOS: lamp环境初始搭建: nginx和apache的使用

 

 

内容参考,非常感谢这位大哥:https://blog.csdn.net/ly199108171231/article/details/53536093https://blog.csdn.net/weixin_37657720/article/details/80082568

相关文章:

  • 2021-05-17
  • 2021-06-09
  • 2021-06-08
  • 2021-12-04
  • 2022-01-15
  • 2022-12-23
猜你喜欢
  • 2021-11-20
  • 2021-12-12
  • 2022-12-23
  • 2021-05-22
  • 2021-11-20
  • 2022-01-20
相关资源
相似解决方案