Abu Hurairah and Abu Saeed Khudri reported,

They both reported that the Messenger of Allah ﷺ saw some phlegm on the wall of the mosque. He took a pebble and scraped it off, then said, "When one of you needs to expel phlegm, let him not spit in front of his face nor to his right. Let him spit to his left or under his left foot."

Ibn Majah 761

Sahih

حدثنا محمد بن عثمان العثماني أبو مروان حدثنا إبراهيم بن سعد عن ابن شهاب عن حميد بن عبد الرحمن بن عوف

عن أبي هريرة وأبي سعيد الخدري

أنهما أخبراه أن رسول الله ﷺ رأى نخامة في جدار المسجد فتناول حصاة فحكها ثم قال إذا تنخم أحدكم فلا يتنخمن قبل وجهه ولا عن يمينه وليبزق عن شماله أو تحت قدمه اليسرى

ابن ماجه 761صحيح
Contents
Reference
Commentary
Ayat
Collection
Sunan Ibn Majah
Book
Mosques and congregations
Chapter
Disliking phlegm in the masjid
Numbering
Darussalam 761
Ibn Majah 761