The disciplinary action stems from separate incidents involving a misdemeanor weapons charge and misdemeanor marijuana possession charge.
Foster will miss the season opener at Minnesota and a home game versus the Detroit Lions. He is eligible to return to San Francisco's roster on Sept. 17.
The second-year linebacker out of Alabama will be eligible to participate in all preseason practices and games.
"I accept the League's decision and am sorry that my mistakes have hurt my team," said Foster in a statement. "I have a responsibility to the 49ers, our fans and our community, and I am committed to learning from this situation and making better choices in the future. The support I have received over the last five months has been humbling, and I do not take it for granted."
Foster pleaded no-contest in June to a misdemeanor weapons charge in Santa Clara County (Calif.) Superior Court. He was sentenced to two years of probation, 240 hours of community service and $235 in fines.
Foster escaped another legal problem when prosecutors in Alabama dropped a misdemeanor marijuana possession charge against him stemming from his arrest in January.
The 24-year-old Foster originally was facing two felony domestic violence charges and a felony weapons charge in the case before his former girlfriend recanted accusations she made against him.
A judge dismissed the felony charges and reduced the weapons charge to a misdemeanor after hearing the ex-girlfriend's testimony during Foster's preliminary hearing in May.
Foster missed the early portion of the 49ers' offseason program but rejoined the team on May 24 after the felony charges were dismissed.
"Our organization understands and supports the League's decision," said San Francisco general manager John Lynch in a statement. "Although we are disappointed that Reuben will not be with our team for the first two games of the season, we will continue to work with him on making better decisions and eliminating unnecessary distractions. We are encouraged to see Reuben take responsibility for his mistakes, and hopeful that he has learned from them as well."
Foster ranked second on the 49ers in tackles with 72 despite missing five games because of a high ankle sprain and another game with back spasms. He was named the NFL's Defensive Rookie of the Month in November.
The Butkus Award winner at Alabama as the nation's top linebacker, Foster slid to the bottom of the first round as the No. 31 pick in the 2017 NFL Draft because of his character and medical issues (shoulder surgery after his final season with the Crimson Tide).