דילוג לתוכן
  • דף הבית
  • קטגוריות
  • פוסטים אחרונים
  • משתמשים
  • חיפוש
  • חוקי הפורום
כיווץ
תחומים

תחומים - פורום חרדי מקצועי

💡 רוצה לזכור קריאת שמע בזמן? לחץ כאן!
  1. דף הבית
  2. תכנות
  3. מספר שרתי אינטרנט בשרת אחד

מספר שרתי אינטרנט בשרת אחד

מתוזמן נעוץ נעול הועבר תכנות
12 פוסטים 3 כותבים 237 צפיות
  • מהישן לחדש
  • מהחדש לישן
  • הכי הרבה הצבעות
התחברו כדי לפרסם תגובה
נושא זה נמחק. רק משתמשים עם הרשאות מתאימות יוכלו לצפות בו.
  • dovidD מנותק
    dovidD מנותק
    dovid ניהול
    כתב ב נערך לאחרונה על ידי
    #3

    אכן אל תעבוד לפי פורטים.

    1. האפשרות המידיית והיותר פשוטה זה לשנות את הפורט של הapach ל8080 למשל, ולהאזין הכל דרך הnginx ולהפנות לפי ההוסט לאיפה שצריך.
    2. תוכל גם לסלק את האפאצ' כפי שהצעת ולעבור לLEMP (לא LNMP כי nginx נקרא בפועל n-ginix ובעברית אנג'יניקס, אז זה E).
      זה פחות קל ואולי יותר מומלץ בגלל ריכוזיות (מקום אחד לכל ההגדרות, הnginx).

    מנטור אישי למתכנתים (ולא רק) – להתקדם לשלב הבא!

    בכל נושא אפשר ליצור קשר dovid@tchumim.com

    תגובה 1 תגובה אחרונה
    3
    • ח מנותק
      ח מנותק
      חוקר
      כתב ב נערך לאחרונה על ידי
      #4

      הלכתי על lemp.
      מה שהוצרכתי לעשות היה ס"ה להתקין את phpfpm.
      עדיין לא שיניתי את פורט 80 עד שהכל יסודר.
      למעשה זה עובד לי להריץ PHP עם הNGINX.
      אך מה שנותר לי הוא להסתדר עם קובץ התצורה של NGINX.
      העניין הוא שאני משתמש עם YII2 עם ניתובים יפים כמו שמופיע כאן
      https://www.yiiframework.com/doc/guide/2.0/en/start-installation#recommended-nginx-configuration
      אז מצד אחד אני צריך להגדיר שהכל יופנה לindex.php שבתוך התיקיית YII.
      ומצד שני אני רוצה לשלול כמה תיקיות שבהם לא ינותב כלל לYII.
      איך אני אמור לעשות זאת?
      תודה

      תגובה 1 תגובה אחרונה
      0
      • dovidD מנותק
        dovidD מנותק
        dovid ניהול
        כתב ב נערך לאחרונה על ידי
        #5

        https://www.yiiframework.com/wiki/153/using-yii-with-nginx-and-php-fpm?revision=6

        מנטור אישי למתכנתים (ולא רק) – להתקדם לשלב הבא!

        בכל נושא אפשר ליצור קשר dovid@tchumim.com

        ח תגובה 1 תגובה אחרונה
        2
        • ח מנותק
          ח מנותק
          חוקר
          השיב לdovid ב נערך לאחרונה על ידי
          #6

          @dovid
          לא הסתדרתי עם זה.
          הבעיה היא כך, הנתיב האמיתי של תיקיית שורש הינו

          /var/www/public_html/
          

          מאידך התיקיה של YII הינו

          /var/www/public_html/yii/frontend/web
          

          לעומת זאת יש בתקיה הראשית תיקיה כגון api שיש שם סקריפטים של PHP שאני כן רוצה שיהיה אליהם גישה.
          אז למעשה עלי לסדר כמה נקודות.
          בגישה לנתיב הראשי / יפנה ל

          /var/www/public_html/yii/frontend/web/index.php
          

          גישה לקבצים סטטים תיהיה בתוך תיקיית

          /var/www/public_html/yii/frontend/web/
          

          ומאידך DOCUMENT_ROOT שישאר (עבור פעולות שתלויות בזה בPHP)

          /var/www/public_html/
          

          גישה למספר תיקיות מצוינות כגון api יתבצע לפי הנתיב מהשורש הנ"ל. /var/www/public_html/
          כל שאר הניתובים כגון
          http://domain.com/site/login
          יבוצעו לתיקיית YII לקובץ

          /var/www/public_html/yii/frontend/web/index.php
          

          מקוה שכתבתי ברור את הדרישות.
          תודה

          תגובה 1 תגובה אחרונה
          0
          • dovidD מנותק
            dovidD מנותק
            dovid ניהול
            כתב ב נערך לאחרונה על ידי
            #7

            לא הבנתי במה לא הסתדרת עם מה שהבאתי.
            תעשה העתק הדבק, שנה את הנתיבים הבודדים וזהו.

            מנטור אישי למתכנתים (ולא רק) – להתקדם לשלב הבא!

            בכל נושא אפשר ליצור קשר dovid@tchumim.com

            ח תגובה 1 תגובה אחרונה
            1
            • ח מנותק
              ח מנותק
              חוקר
              השיב לdovid ב נערך לאחרונה על ידי
              #8

              @dovid
              אלו ההגדרות ששמתי

              # Implement upstream connection to PHP-FPM
              # "phpfpm" here is a name for this upstream connection, which you can customize
              # I create a custom upstream connection per vhost, to better segregate PHP processes by vhost
              # To do the same, you need a unique upstream name, and a unique filename for your php5-fpm.sock file
              upstream phpfpm {
                  server unix:/var/run/php/php7.2-fpm.sock;
                  #avoid sockets for nginx-fpm on Linux, they are good for BSD
                  #server 127.0.0.1:9000;
              }
              
              server {
                  # Listening on port 80 without an IP address is only recommended if you are not running multiple v-hosts
                  #listen       80;
                  # Bind to the public IP bound to your domain
                  #listen 8888;
                  listen         8888 default_server;
                  listen         [::]:8888 default_server;
              
                  # Specify this vhost's domain name
                  server_name mydomainname.com;
                  root /var/www/public_html;
                  index index.php index.html index.htm;
              
                  # Specify log locations for current site
                  access_log /var/www/mydomainname.com/log/access.log;
                  error_log /var/www/mydomainname.com/log/error.log warn;
              
                  # Typically I create a restrictions.conf file that I then include across all of my vhosts
                  #include conf.d/restrictions.conf;
                  # I've included the content of my restrictions.conf in-line for this example
              
                  # BEGIN restrictions.conf
                  # Disable logging for favicon
                  location = /favicon.ico {
                      log_not_found off;
                      access_log off;
                  }
              
                  # Disable logging for robots.txt
                  location = /robots.txt {
                      allow all;
                      log_not_found off;
                      access_log off;
                  }
              
                  # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
                  location ~ /\. {
                      deny all;
                      access_log off;
                      log_not_found off;
                  }
                  # END restrictions.conf
              
                  # Typically I create a yiiframework.conf file that I then include across all of my yii vhosts
                  #include conf.d/yiiframework.conf;
                  # I've included the content of my yiiframework.conf in-line for this example
              
                  # BEGIN yiiframework.conf
                  # Block access to protected, framework, and nbproject (artifact from Netbeans)
                  location ~ /(protected|framework|nbproject|class) {
                      deny all;
                      access_log off;
                      log_not_found off;
                  }
              
                  # Block access to theme-folder views directories
                  location ~ /themes/\w+/views {
                      deny all;
                      access_log off;
                      log_not_found off;
                  }
              
                  # Attempt the uri, uri+/, then fall back to yii's index.php with args included
                  # Note: old examples use IF statements, which nginx considers evil, this approach is more widely supported
                  location / {
                      #root /var/www/public_html/yii/frontend/web;
                      try_files $uri $uri/ /yii/frontend/web/index.php$is_args$args;
                  }
                  # END yiiframework.conf
              
                  # Tell browser to cache image files for 24 hours, do not log missing images
                  # I typically keep this after the yii rules, so that there is no conflict with content served by Yii
                  location ~* \.(js|css|png|jpg|jpeg|gif|ico|woff2|ttf|woff)$ {
              	root /var/www/public_html/yii/frontend/web;
                      #expires 24h;
                      log_not_found off;
                  }
              
                  # Block for processing PHP files
                  # Specifically matches URIs ending in .php
                  location ~ \.php$ {
                      try_files $uri =404;
              
                      # Fix for server variables that behave differently under nginx/php-fpm than typically expected
                      fastcgi_split_path_info ^(.+\.php)(/.+)$;
                      # Include the standard fastcgi_params file included with nginx
                      include fastcgi_params;
                      fastcgi_param  PATH_INFO        $fastcgi_path_info;
                      fastcgi_index index.php;
                      # Override the SCRIPT_FILENAME variable set by fastcgi_params
                      fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                      # Pass to upstream PHP-FPM; This must match whatever you name your upstream connection
                      fastcgi_pass phpfpm;
                  }
              }
              

              על פניו הכל תקין.
              מלבד שבכתובת הראשית mydomainname.com:8888 זה פותח את הדף index שמופיע ב /var/www/public_html ואם אני מוחק אותו הוא נותן לי שגיאה 403 שזה בעצם אין גישה לאינדקס, ובכל מקרה הוא לא מנתב את הראשי לכתובת המבוקשת
              /var/www/public_html/yii/frontend/web/index.php

              תגובה 1 תגובה אחרונה
              0
              • dovidD מנותק
                dovidD מנותק
                dovid ניהול
                כתב ב נערך לאחרונה על ידי
                #9

                לא הבנתי. ההגדרה שלך ל תואמת לדעתי לנתיבים הנכונים. למיטב הבנתי בroot אתה אמור לכתוב

                root  /var/www/public_html/yii/frontend/web;
                index index.php index.html index.htm;
                

                בtry_file

                    try_files $uri $uri/ /index.php?$args;
                

                לקבצים הסטטיים תניח בינתיים, ותדאג להפעיל מחדש את האנג'ינאיקס על כל שינוי.

                מנטור אישי למתכנתים (ולא רק) – להתקדם לשלב הבא!

                בכל נושא אפשר ליצור קשר dovid@tchumim.com

                ח תגובה 1 תגובה אחרונה
                1
                • ח מנותק
                  ח מנותק
                  חוקר
                  השיב לdovid ב נערך לאחרונה על ידי חוקר
                  #10

                  @dovid
                  אני חייב להשאיר את רוט כנ"ל כי בחלק מהאתר יש לי סקריפטים שלא קשורים לYII, ושם בקוד כתבתי מיקומים לפי המיקום של הרוט, לכן את הרוט השארתי על התיקיה הציבורית האמיתית, ורק מה שאינו קיים לפי הניתוב האמיתי שיופנה לYII בכתובת של התיקיה של הYII.
                  וכן כי סקריפטים אלו נמצאים במיקום /var/www/public_html/api ולא בתוך /var/www/public_html/yii/frontend/web
                  הבעיה תופסת רק בכתובת הראשית ממש שזה קיים גם באמת (כי התיקיה public_html קיימת), ולמעשה שם אני כן רוצה שיופנה לתיקית YII

                  ח תגובה 1 תגובה אחרונה
                  0
                  • ח מנותק
                    ח מנותק
                    חוקר
                    השיב לחוקר ב נערך לאחרונה על ידי
                    #11

                    @חוקר אמר במספר שרתי אינטרנט בשרת אחד:

                    @dovid
                    אני חייב להשאיר את רוט כנ"ל כי בחלק מהאתר יש לי סקריפטים שלא קשורים לYII, ושם בקוד כתבתי מיקומים לפי המיקום של הרוט, לכן את הרוט השארתי על התיקיה הציבורית האמיתית, ורק מה שאינו קיים לפי הניתוב האמיתי שיופנה לYII בכתובת של התיקיה של הYII.
                    וכן כי סקריפטים אלו נמצאים במיקום /var/www/public_html/api ולא בתוך /var/www/public_html/yii/frontend/web
                    הבעיה תופסת רק בכתובת הראשית ממש שזה קיים גם באמת (כי התיקיה public_html קיימת), ולמעשה שם אני כן רוצה שיופנה לתיקית YII

                    מצאתי פיתרון זה מגדיר סיפיציפי את הURL כשהוא ללא שום פרמטר אל הנתיב הראשי של YII

                       location = / {
                            try_files $uri /yii/frontend/web/index.php/ /yii/frontend/web/index.php;
                        }
                    

                    ייתכן שניתן להגדיר את זה יותר חכם, אשמח לדעת מה אמור להיות הפקודה הנכונה שיפנה מיידית לURL המבוקש ללא בדיקה האם קיים או לא.

                    תגובה 1 תגובה אחרונה
                    0
                    • ח מנותק
                      ח מנותק
                      חוקר
                      כתב ב נערך לאחרונה על ידי
                      #12

                      ב"ה הסתדרתי עם הכל, כולל עצירת האפאצ'י ומעבר הכל לnginx.
                      להלן ההגדרות המלאות למי שזה יכול לעזור

                      # Implement upstream connection to PHP-FPM
                      # "phpfpm" here is a name for this upstream connection, which you can customize
                      # I create a custom upstream connection per vhost, to better segregate PHP processes by vhost
                      # To do the same, you need a unique upstream name, and a unique filename for your php5-fpm.sock file
                      upstream phpfpm {
                          server unix:/var/run/php/php7.2-fpm.sock;
                          #avoid sockets for nginx-fpm on Linux, they are good for BSD
                          #server 127.0.0.1:9000;
                      }
                      
                      server {
                          # Listening on port 80 without an IP address is only recommended if you are not running multiple v-hosts
                          # Bind to the public IP bound to your domain
                          listen 80;
                          listen 443 ssl;
                      
                          ssl_certificate /etc/letsencrypt/live/mydomainname.com/fullchain.pem; # managed by Certbot
                          ssl_certificate_key /etc/letsencrypt/live/mydomainname.com/privkey.pem; # managed by Certbot
                          include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
                          ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
                      
                          # Specify this vhost's domain name
                          server_name mydomainname.com;
                          root /var/www/public_html;
                          index index.php index.html index.htm;
                      
                          # Specify log locations for current site
                          access_log /var/www/mydomainname.com/log/access.log;
                          error_log /var/www/mydomainname.com/log/error.log warn;
                      
                          # Typically I create a restrictions.conf file that I then include across all of my vhosts
                          #include conf.d/restrictions.conf;
                          # I've included the content of my restrictions.conf in-line for this example
                      
                          # BEGIN restrictions.conf
                          # Disable logging for favicon
                          location = /favicon.ico {
                              log_not_found off;
                              access_log off;
                          }
                      
                          # Disable logging for robots.txt
                          location = /robots.txt {
                              allow all;
                              log_not_found off;
                              access_log off;
                          }
                      
                          # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
                          location ~ /\. {
                              deny all;
                              access_log off;
                              log_not_found off;
                          }
                          # END restrictions.conf
                      
                          # Typically I create a yiiframework.conf file that I then include across all of my yii vhosts
                          #include conf.d/yiiframework.conf;
                          # I've included the content of my yiiframework.conf in-line for this example
                      
                          # BEGIN yiiframework.conf
                          # Block access to protected, framework, and nbproject (artifact from Netbeans)
                          location ~ /(protected|framework|nbproject) {
                              deny all;
                              access_log off;
                              log_not_found off;
                          }
                      
                          # Block access to theme-folder views directories
                          location ~ /themes/\w+/views {
                              deny all;
                              access_log off;
                              log_not_found off;
                          }
                      
                          # Attempt the uri, uri+/, then fall back to yii's index.php with args included
                          # Note: old examples use IF statements, which nginx considers evil, this approach is more widely supported
                          location / {
                              #root /var/www/public_html/yii/frontend/web;
                              try_files $uri $uri/ /yii/frontend/web/index.php$is_args$args;
                          }
                          # END yiiframework.conf
                      
                          location = / {
                      	#rewrite /yii/frontend/web/index.php last;
                      	try_files $uri /yii/frontend/web/index.php/ /yii/frontend/web/index.php;
                          }
                      
                      
                          # Tell browser to cache image files for 24 hours, do not log missing images
                          # I typically keep this after the yii rules, so that there is no conflict with content served by Yii
                          location ~* \.(js|css|png|jpg|jpeg|gif|ico|woff2|ttf|woff)$ {
                      	root /var/www/public_html/yii/frontend/web;
                              #expires 24h;
                              log_not_found off;
                          }
                      
                          # Block for processing PHP files
                          # Specifically matches URIs ending in .php
                          location ~ \.php$ {
                              try_files $uri =404;
                      
                              # Fix for server variables that behave differently under nginx/php-fpm than typically expected
                              fastcgi_split_path_info ^(.+\.php)(/.+)$;
                              # Include the standard fastcgi_params file included with nginx
                              include fastcgi_params;
                              fastcgi_param  PATH_INFO        $fastcgi_path_info;
                              fastcgi_index index.php;
                              # Override the SCRIPT_FILENAME variable set by fastcgi_params
                              fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                              # Pass to upstream PHP-FPM; This must match whatever you name your upstream connection
                              fastcgi_pass phpfpm;
                          }
                      }
                      server {
                          listen 80;
                          listen 443 ssl;
                          ssl_certificate /etc/letsencrypt/live/api.mydomainname.com/fullchain.pem; # managed by Certbot
                          ssl_certificate_key /etc/letsencrypt/live/api.mydomainname.com/privkey.pem; # managed by Certbot
                          include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
                          ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
                       
                              #root /var/www/sub.test.com;
                              #index index.html index.htm index.nginx-debian.html;
                      
                              server_name api.mydomainname.com www.api.mydomainname.com;
                      
                          location / {
                              proxy_pass http://127.0.0.1:8080;
                              #proxy_set_header Host $host;
                              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                              proxy_set_header X-Forwarded-Proto $scheme;
                              # the next 3 lines are for cocket protocol nedded both for web ui and mobile app
                              proxy_http_version 1.1;
                              proxy_set_header Upgrade $http_upgrade;
                              proxy_set_header Connection "upgrade";
                          }
                      }
                      

                      תודה לעוזרים

                      תגובה 1 תגובה אחרונה
                      2

                      בא תתחבר לדף היומי!
                      • התחברות

                      • אין לך חשבון עדיין? הרשמה

                      • התחברו או הירשמו כדי לחפש.
                      • פוסט ראשון
                        פוסט אחרון
                      0
                      • דף הבית
                      • קטגוריות
                      • פוסטים אחרונים
                      • משתמשים
                      • חיפוש
                      • חוקי הפורום