linux修改对外访问ip_linux 同一个ip 绑定两个不同的域名 访问两个不同的项目

e86e78ca13df32c96bc0bba21ccdb035.png

phubing 2020-01-08 11:52:17

bfb38d823f7079c4f3d18cc4d67382e6.png

267

dc29e110da80a2acd5ca6f8a7ef1fec9.png

收藏
分类专栏: Nginx 文章标签: Nginx 域名 IP
版权

用两个不同的域名绑定同一个ip访问两个不同的项目是完全可以做到的,远没有想象的那么复杂,使用服务器环境LNMP
要实现这个功能首先需要配置nginx
打开nginx的配置文档(nginx.conf)


  1. server {

  2. listen 80;          //端口

  3. server_name www.xxxxx.com;      //域名

  4. access_log xxxxx;      //日志存储的位置

  5. root xxxxx;  //项目根路径

  6. index index.html index.htm index.php;

  7. fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;

  8. location / {

  9. try_files $uri $uri/ /index.php?$query_string;

  10. }

  11. location /nginx_status {

  12. stub_status on;

  13. access_log off;

  14. allow xxx.xxx.xx.xx;

  15. deny all;

  16. }

  17. location ~ [^/].php(/|$) {

  18. #fastcgi_pass remote_php_ip:9000;

  19. fastcgi_pass unix:/dev/shm/php-cgi.sock;

  20. fastcgi_index index.php;

  21. include fastcgi.conf;

  22. }

  23. location ~ .*.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {

  24. expires 30d;

  25. access_log off;

  26. }

  27. location ~ .*.(js|css)?$ {

  28. expires 7d;

  29. access_log off;

  30. }

  31. }


以上只是一个项目的配置,同样的我们想同一个服务器打在两个不同的项目那么所需要做的就是复制相同的一份代码,指定不同的项目路径


  1. server {

  2. listen 80;    //端口

  3. server_name www.xxxx.com;    //域名

  4. access_log /data/wwwlogs/access_nginx.log combined;

  5. root xxxxxxx;    //项目根路径

  6. index index.html index.htm index.php;

  7. fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;

  8. location / {

  9. try_files $uri $uri/ /index.php?$query_string;

  10. }

  11. location /nginx_status {

  12. stub_status on;

  13. access_log off;

  14. allow 127.0.0.1;

  15. deny all;

  16. }

  17. location ~ [^/].php(/|$) {

  18. #fastcgi_pass remote_php_ip:9000;

  19. fastcgi_pass unix:/dev/shm/php-cgi.sock;

  20. fastcgi_index index.php;

  21. include fastcgi.conf;

  22. }

  23. location ~ .*.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {

  24. expires 30d;

  25. access_log off;

  26. }

  27. location ~ .*.(js|css)?$ {

  28. expires 7d;

  29. access_log off;

  30. }

  31. }


要想实现这个功能的中心就在于域名的不同和项目根路径的不同

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值