Linux服务器下Nginx与Apache共存

解决思路:

将nginx作为代理服务器和web服务器使用,nginx监听80端口,Apache监听除80以外的端口,我这暂时使用8080端口。

nginx.conf 位置:/etc/nginx/nginx.conf

在nginx.conf中 http {}内添加:

server {
    listen       80;
    server_name  www.one.ityangs.cn one.ityangs.cn 替换成你要反向代理的域名;

	location / {
        proxy_pass              http://127.0.0.1:8080;
        proxy_redirect          off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

重启nginx

将apache的配置文件ports.conf 中listen的端口号改为8080;

将apache的域名配置文件中端口号改为8080

重启apache

下面的我没有测试

Nginx下的网站:

在nginx.conf中 http {}添加

server {
    listen       	80;
    server_name    two.ityangs.cn www.two.ityangs.cn;
    root   /www/two;
    location /{
        index  index.html index.htm index.php;
        if (!-e $request_filename) {
        rewrite  ^(.*)$  /index.php?s=$1  last;
        break;
        }
        error_page 404  /var/www/html/404.html;
    }
    location ~ \.php(.*)$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  PATH_INFO  $fastcgi_path_info;
        fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
        include        fastcgi_params; 
    }
}

转载自:https://blog.csdn.net/ITYang_/article/details/53907937

猜你喜欢

转载自blog.csdn.net/u010071211/article/details/81985686